JS代码:
new Vue({
el : '#app',
data : {
aa : 1
}
})
页面上打印:
@{{ aa }}
正常应该能在页面上打印出 “1” 才对,但是一直报错,报错信息:Property or method "aa" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option.
引用的VUE是通过Laravel框架下npm安装后生成的app.js。换成官网下载的独立的vue.js就不会报错 页面上也能打印出“1”。这是为啥,初学者,有点不大明白,是不是生成的这个app.js有问题。还是我package.json配的有问题
package.json:
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.15.3",
"bootstrap-sass": "^3.3.7",
"cross-env": "^3.2.3",
"jquery": "^3.1.1",
"laravel-mix": "0.*",
"lodash": "^4.17.4",
"vue": "^2.1.10"
}
}
有没有大神遇到过这个问题 帮忙解答一下 感激不尽
雷雷
使用vue-cli跟引用vue.js有点不一样,在vue-cli里面data是一个方法,不是一个对象,应该写成