小程序mpvue框架

小程序开发-mpvue构建小程序项目-1-踩坑

2018-08-01  本文已影响675人  刘小胖LJX

mpvue-entry 插件引入

参考文档: npm-mpvue-entry

重点参考文档: https://github.com/F-loat/mpvue-entry

参考配置文档: mpvue-issue-F-loat的回答

npm i mpvue-entry --save

操作了半天,mpvue-entry的作者为了方便大家使用,开源了基于mpvue-entry的模版,大家可以直接使用这个quickStart进行构建项目

mpvue-entry-quickStart 项目地址: mpvue-entry-quickStart

 $ npm install -g vue-cli
 $ vue init F-loat/mpvue-quickstart my-project
 $ cd my-project
 $ npm install
 $ npm run dev

mpvue-entry-quickStart模版使用方式

新增页面

参考文档: https://github.com/F-loat/mpvue-entry

// pages.js
module.exports = [
 {
   path: 'pages/news/list', // 页面路径,同时是 vue 文件相对于 src 的路径,必填
   config: { // 页面配置,即 page.json 的内容,可选
     navigationBarTitleText: '文章列表',
     enablePullDownRefresh: true
   }
 }
]

mpvue-entry 使用注意事项

分包与主包的配置

module.exports = [
  // 主包
  {
    path: 'pages/cardList/index', // 页面路径,同时是 vue 文件相对于 src 的路径
  }, {
    path: 'pages/card/index'
  }, 
  // 分包
  {
    path: 'packageA/logs',
    subPackage: true,
    config: { // 页面配置,即 page.json 的内容
      navigationBarTitleText: '查看启动日志'
    }
  }
]

小程序默认tabBar配置

参考文档: 小程序文档-配置

用途

配置方式

// 主 main.js 文件
import Vue from 'vue'
import App from '@/App'
import store from '@/store'

Vue.config.productionTip = false
App.store = store
App.mpType = 'app'

const app = new Vue(App)
app.$mount()

export default {
  // 这个字段走 app.json
  config: {
    pages: [],
    window: {
      backgroundTextStyle: 'light',
      navigationBarBackgroundColor: '#fff',
      navigationBarTitleText: 'WeChat',
      navigationBarTextStyle: 'black'
    },
    // tabBar 配置
    tabBar: {
      backgroundColor: "#fafafa",
      borderStyle: "white",
      selectedColor: "#b4282d",
      color: "#666",
      list: [
        {
          pagePath: "pages/cardList/index",
          iconPath: "static/images/ic_menu_choice_nor.png",
          selectedIconPath: "static/images/ic_menu_choice_pressed.png",
          text: "cardlist"
        },
        {
          pagePath: "pages/card/index",
          iconPath: "static/images/ic_menu_choice_nor.png",
          selectedIconPath: "static/images/ic_menu_choice_pressed.png",
          text: "card"
        },
      ]
    }
  }
}

BY-Luca_LJX(git地址

上一篇 下一篇

猜你喜欢

热点阅读