http://mpvue.com/
# 全局安装 vue-cli
$ npm install --global vue-cli
# 创建一个基于 mpvue-quickstart 模板的新项目
$ vue init mpvue/mpvue-quickstart my-project
# 安装依赖
$ cd my-project
$ npm install
# 启动构建
$ npm run dev
小程序中设置页面颜色时候需要设置page,否则无效。
除了Vue本身的生命周期外,mpvue还兼容了小程序生命周期,这部分生命周期钩子的来源于微信小程序的Page,除特殊情况外,不建议使用小程序的生命周期钩子。
在import 的时候导入文件时候不能使用绝对路径,必须使用相对路径(特别是vuex中)
# 引入并注册
import Fly from 'flyio/dist/npm/wx'
// 配置fly进行ajax请求
let fly = new Fly
Vue.prototype.$fly = fly
# 使用
beforeMount() {
this.$fly.get(MOVIE_URL)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
}
错误:[vuex] unknown mutation type: receive_list(有可能是mutation type引用变量问题,可以先不用mutation-type单独模块抽取变量)
否则报错:VM1218:5 pages/detail/main.json 文件解析错误 SyntaxError: Unexpected end of JSON input
使用this.$mp.query.index
取代onLoad中的options
Cannot read property ‘call’ of undefined
VM11460:1 thirdScriptError
sdk uncaught third Error
Cannot read property 'call' of undefined
TypeError: Cannot read property 'call' of undefinedCannot read property 'call' of undefined TypeError: Cannot read property 'call' of undefined
# 解决方法:
打包之后这个警告也还在,并且报错 Uncaught TypeError: Cannot read property 'call' of undefined。解决方法是在 webpack.base.conf.js 的 module 下加 noParse: [/ali-oss/], 在编译时忽略上面的警告。再之后就出现上篇开头描述的情况。