admin管理员组文章数量:1415475
I am trying to call a parent/root level method on a child ponent in Vue.js, but I keep getting a message saying TypeError: this.addStatusClass is not a function
.
Vueponent('spmodal', {
props: ['addStatusClass'],
created: function() {
this.getEnvironments();
},
methods: {
getEnvironments: function() {
this.addStatusClass('test');
}
}
});
new Vue({
el: '#app',
methods: {
addStatusClass(data) {
console.log(data);
}
}
});
Here is a full JSBIN example: ,console,output
If I call this.$parent.addStatusClass('test');
it works fine, but based on the Vue.js documentation, this is bad practice and I should be using props which is not working.
I am trying to call a parent/root level method on a child ponent in Vue.js, but I keep getting a message saying TypeError: this.addStatusClass is not a function
.
Vue.ponent('spmodal', {
props: ['addStatusClass'],
created: function() {
this.getEnvironments();
},
methods: {
getEnvironments: function() {
this.addStatusClass('test');
}
}
});
new Vue({
el: '#app',
methods: {
addStatusClass(data) {
console.log(data);
}
}
});
Here is a full JSBIN example: http://jsbin./tomorozonu/edit?js,console,output
If I call this.$parent.addStatusClass('test');
it works fine, but based on the Vue.js documentation, this is bad practice and I should be using props which is not working.
1 Answer
Reset to default 6specifying the prop does nothing on its own, you have to actually pass something to it from the parent - in this case, the function.
<spmodal :add-status-class="addStatusClass"></spmodal>
本文标签: javascriptHow can I access a parent method from child component in VuejsStack Overflow
版权声明:本文标题:javascript - How can I access a parent method from child component in Vue.js? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745148556a2644810.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论