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"
}
}
有沒有大神遇過這個問題 幫忙解答一下 感激不盡
#迷茫2017-05-27 17:44:00
使用vue-cli跟引用vue.js有點不一樣,在vue-cli裡面data是一個方法,不是一個對象,應該寫成
data(){
return{
aa:11
}
}