基于mint-ui的移动应用开发案例三(首页)
2017-11-30 09:51
537 查看
本节主要包含以下内容:
首页大致布局
vuex进行底部tabbar的显示与隐藏控制和tab选中控制
mint-cell-swipe组件的使用
在index.js中定义的状态state和mutations也是这两个相关的:
mutation_types.js
this.$store.commit('TOGGLE_FOOTER'); 就可以了。
2.首页布局与mint-cell-swipe的使用
首页的实现很简单,就是一个header和一个可以右滑菜单的cell,这些都是mint里面的组件,可以直接使用,先上代码:
另外,mt-cell-swipe组件的属性right接收一个对象,其中content表示右滑后显示的内容,style表示content的样式,handler()表示点击content对应内容后的处理函数,这里是弹出一个信息对话框,然后根据选择“确认”“取消”来执行不同的动作。本例只是简单的模拟一下各控件的使用,不涉及数据操作。
首页大致布局
vuex进行底部tabbar的显示与隐藏控制和tab选中控制
mint-cell-swipe组件的使用
1.vuex的引入与使用
首先在state文件夹中新建一个mutation_types.js用于存放要提交的动作,和一个index.js主要配置js。这里主要是定义了两个动作,一个叫TOOGLE_FOOTER用于控制底部bar的显示与否,一个叫SELECTED_TAB用于控制底部tab选中的标签。在index.js中定义的状态state和mutations也是这两个相关的:
mutation_types.js
export const TOGGLE_FOOTER = 'TOGGLE_FOOTER'; export const SELECT_TAB = 'SELECT_TAB';index.js
import Vue from 'vue' import Vuex from 'vuex' import * as types from './mutation-types'//导入 Vue.use(Vuex); const store = new Vuex.Store({ state: { footerVisible: true,//底部bar显示的状态 selectedTab: 'main'//选中的tab标签 }, mutations: { [types.TOGGLE_FOOTER] (state) { state.footerVisible = !state.footerVisible }, [types.SELECT_TAB](state, val){ state.selectedTab = val } } }); export default store接着在main.js中引入状态管理:
import Vue from 'vue' import App from './App' import router from './router' import MintUI from 'mint-ui' import store from './store/index.js'//引入 import echarts from 'echarts' Vue.prototype.$echarts = echarts Vue.use(MintUI); /*Vue.config.productionTip = false;*/ new Vue({ el: '#app', router, store,//使用 template: '<App/>', components: {App} });接下来我们的页面要想使用这些状态或者想要改变这些状态,只需要 this.$store.state.footerVisible 或者
this.$store.commit('TOGGLE_FOOTER'); 就可以了。
2.首页布局与mint-cell-swipe的使用
首页的实现很简单,就是一个header和一个可以右滑菜单的cell,这些都是mint里面的组件,可以直接使用,先上代码:<template> <div id="index"> <mt-header fixed title="首页"></mt-header> <div class="content"> <mt-cell-swipe :right="right" title="未读通知"> <span><mt-badge type="error">10</mt-badge></span> </mt-cell-swipe> </div> </div> </template> <style scoped> .content { margin-top: 40px; } </style> <script> import {Toast} from 'mint-ui'; export default { data(){ return { right: [ { content: '删除', style: {background: 'red', color: '#fff', width: '50px', textAlign: 'center'}, handler: () => this.$messagebox({ title: '提示', message: '确定执行此操作?', showCancelButton: true }).then((action) => { if (action === 'confirm') { Toast({message: '删除成功'}) } else { } }) } ] } }, created(){ let _footer = this.$store.state.footerVisible; if (!_footer) { this.$store.commit('TOGGLE_FOOTER'); } this.$store.commit('SELECT_TAB', 'main') } } </script>可以看到,在钩子函数created中,获取了当前footerbar的显示状态,如果是false的话,就变成true显示;接着将选中的tab标签设置为main。
另外,mt-cell-swipe组件的属性right接收一个对象,其中content表示右滑后显示的内容,style表示content的样式,handler()表示点击content对应内容后的处理函数,这里是弹出一个信息对话框,然后根据选择“确认”“取消”来执行不同的动作。本例只是简单的模拟一下各控件的使用,不涉及数据操作。
相关文章推荐
- 基于mint-ui的移动应用开发案例五(个人中心)
- 基于mint-ui的移动应用开发案例二(项目搭建)
- 基于mint-ui的移动应用开发案例四(应用中心)
- 基于mint-ui的移动应用开发案例一(简介)
- 移动开发的比较理想的应用案例
- Jquery+WeUI开发移动APP应用
- Origin:基于以太坊的58同城 | DApp开发与应用案例
- 基于以太坊开发的类似58同城的DApp开发与应用案例
- 基于Mono跨平台移动应用开发框架发布Xamarin 3.0
- 跨平台移动开发实战(五)------基于Jquery mobile开发UI的核心要素
- 5分钟开发一个简单的基于HTML5的移动应用
- APICloud移动应用定制服务——APP开发案例
- 10款基于Html的移动应用开发框架
- 基于RED5&Flex流媒体应用实战开发(附多人聊天室、在线秀场及视频会议三大案例)
- Smobiler基于.NET框架开发移动应用内部系统—消息列表功能(开发日志六)
- HTML5开发移动web应用——SAP UI5篇(4)
- Tizen(泰泽)移动开发平台 - 基于html5的应用开发环境
- Smobiler基于.NET框架开发移动应用内部系统—工作单功能(开发日志七)
- 移动网络应用开发中,使用 HTTP 协议比起使用 socket 实现基于 TCP 的自定义协议有哪些优势?
- 浅谈跨平台移动应用开发AppCan 移动端UI2.0框架