是否可以在VueJS中设置动态事件?我尝试构建一个动态表单作为包含可以监听所有内容的输入的组件。这里是一个例子:
import Vue from 'vue';
let formItems = {
{type: 'checkbox', id: 'some-id', on:'change', model: 'someId'},
{type: 'url', id: 'another-id', on:'keyup', model:'anotherId'},
};
let params = {
someId: true,
anotherId: 'http://www.example.com',
};
new Vue({
el: '#app',
data: {
formItems: formItems,
params: params,
},
methods: {
checkInputParams(e) {
e.preventDefault();
// Do some stuff.
}
}
});Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.3.4/vue.js"></script>
<div id="app">
<div class="form-group" v-for="item in formItems">
<input type="checkbox" <!-- Also need a workaround for dynamic type and v-model -->
:id="item.id"
:class="(item.class ? …Run Code Online (Sandbox Code Playgroud)