在gorails教程上做了一切,但是出了点问题。 Chrome中的错误消息:
Uncaught TypeError: Cannot read property 'props' of undefined
at normalizeProps (vue.runtime.esm.js?ff9b:1291)
at mergeOptions (vue.runtime.esm.js?ff9b:1363)
at mergeOptions (vue.runtime.esm.js?ff9b:1372)
at Vue$3.Vue._init (vue.runtime.esm.js?ff9b:4268)
at new Vue$3 (vue.runtime.esm.js?ff9b:4384)
at HTMLDocument.eval (hello_vue.js?94ab:29)
at Object.t.dispatch (turbolinks.self-)
at r.t.Controller.r.notifyApplicationAfterPageLoad ...)
at r.t.Controller.r.pageLoaded (t...)
at turbolinks.self...
Hello_vue文件:
import Vue from 'vue'
import TurbolinksAdapter from "vue-turbolinks"
import VueResource from "vue-resource"
Vue.use(VueResource);
document.addEventListener('turbolinks:load', () => {
Vue.http.headers.common["X-CSRF-Token"] = document.querySelector('meta[name="csrf-token"]').getAttribute("content");
var element = document.getElementById("team-form")
if(element != null){
var team = JSON.parse(element.dataset.team);
var players_attributes = JSON.parse(element.dataset.playersAttributes);
players_attributes.forEach(function(player){
player._destroy = null
})
team.players_attributes = players_attributes;
var app = new Vue({
el: element,
mixins: [TurbolinksAdapter],
data: function(){
return { team: team }
},
methods: {
addPlayer: function(){
team.players_attributes.push({
id: null,
name: "",
_destroy: null
})
}
}
});
}
});
据我所知,在App对象初始化时出错,但我无法理解究竟是什么。我做得对。
答案 0 :(得分:11)
错误 mixins:[TurbolinksAdapter]
删除该行并添加 Vue.use(TurbolinksAdapter); 后 Vue.use(VueResource); 这一切都有效
答案 1 :(得分:1)
我通过拼错Vue mixins数组中的变量来解决这个问题。 例如:
import file from '../folder/with/file'
export default: {
mixins: [
fil
]
}
应该是
import file from '../folder/with/file'
export default: {
mixins: [
file
]
}