var MainTable = Vue.extend({
template: "<ul>" +
"<li v-for='(set,index) in settings'>" +
"{{index}}) " +
"{{set.title}}" +
"<button @click='changeSetting(index)'> Info </button>" +
"</li>" +
"</ul>",
data: function() {
return data;
}
});
Vue.component("main-table", MainTable);
data.settingsSelected = {};
var app = new Vue({
el: "#settings",
data: data,
methods: {
changeSetting: function(index) {
data.settingsSelected = data.settings[index];
}
}
});
使用上面的代码,单击按钮时会发生以下错误。
[Vue警告]:属性或方法“ changeSetting”未在实例上定义,但在渲染期间被引用。确保在data选项中声明反应性数据属性。(位于中
<MainTable>
)
同样,如果有人像我一样挣扎,请注意,方法是区分大小写的词:
“方法”应该是“方法”