我正在一起使用datatable和vuejs。Datatable位于vuejs组件中,并由vuejs组件成功初始化。但是,对于如何使用vuejs方法,单击datatable行中的复选框元素,我有一些疑问。
{
"title": "Listeleme", "data": "a",
"render": function (data, type, row) {
if (data === true) {
return '<input type="checkbox" id="A' + row.id + '" onclick="checkboxChange(this)" data-role="checkbox" data-type="a" checked>';
} else {
return '<input type="checkbox" id="A' + row.id + '" onclick="checkboxChange(this)" data-role="checkbox" data-type="a">';
}
}
},我需要将onclick="checkboxChange(this)"改为v-on:click="checkboxChange",以访问vuejs组件方法。
注意:如果我像上面那样直接写vuejs方法名,就不能访问该方法。它只是什么都不做
谢谢。
发布于 2019-09-24 14:12:44
找到了解决办法。
将Vue应用程序实例添加到窗口
window.application= new Vue({
});和创建的组件
const someComponent= Vue.component('some-component',{
methods:{
vueJSFunction:function(){
}
}});我可以从组件外部访问VueJS组件方法。
function someFunction(obj) {
window.Application.$children[0].vueJSFunction();
}https://stackoverflow.com/questions/57921921
复制相似问题