html - 复选框的Vue更改事件不起作用
问题描述
我正在使用VUE传递该功能,并且在检查复选框时,该功能不会由更改事件触发。我不确定问题是否是因为我将它写在已安装或其他任何东西上。
mounted() {
var self = this;
let id = this.$route.params.id;
var chkInfo = [];
chk.where("partId", "==", id).get()
.then(function (querySnapshot) {
querySnapshot.forEach(function (doc) {
var data = doc.data();
chkInfo.push({ chk_id: doc.id, d: data.detail, s: data.sequence, status: data.status });
});
let html = '';
for (let i = 0; i < chkInfo.length; i++) {
html += `
<li class="todo-item">
<input type="checkbox" value="" @change="updateTodo()" class="todo-item__checkbox">
<label class="word">${chkInfo[i].d}</label>
</li>
`;
}
self.todoList = html;
})
}
Vue 的模板。我使用 componentKey 重新加载组件,以便数据可以动态填充到界面中。
<section>
<label>Checklist:<br/></label>
<input v-model.trim="newTodo" id="todo-box" placeholder=" Add new todo"/>
<button type="submit" @click.prevent="addTodo()" class="new-todo-button" :disabled="!todoFilled">Add</button>
<ul class="todo-list">
<div v-html="todoList"></div>
<div v-html="addList" :key="listKey"></div>
</ul>
</section>
解决方案
用模板用 Vue 的方式来做怎么样?
<template>
<div>
<div v-for="(info, index) in chkInfo" :key="index">
<li class="todo-item">
<input type="checkbox" v-model="info.d" @change="updateTodo(info.d)" class="todo-item__checkbox" />
<label class="word">{{info.d}}</label>
</li>
</div>
</div>
</template>
<script>
export default {
data() {
return {
chkInfo: []
}
},
mounted() {
let id = this.$route.params.id;
chk.where("partId", "==", id).get()
.then(function (querySnapshot) {
querySnapshot.forEach(function (doc) {
var data = doc.data();
chkInfo.push({ chk_id: doc.id, d: data.detail, s: data.sequence, status: data.status });
});
})
}
}
</script>
如果你真的不能修改模板,你应该将它声明为 vue 实例之外的全局函数。
推荐阅读
- javascript - 在 Glidejs 中轮播设置为自动播放时的触发功能
- ntp - 修复没有闰秒的旧 ntp 服务器
- javascript - 使用javascript获取属性值
- swift - 如何仅在长按手势 SwiftUI 时打开菜单
- javascript - 使用基于不同地图的值的键创建地图?
- firebase - Firebase 云函数:TypeError snapshot.forEach 不是函数
- reactjs - 组件中的选择器不是最新的
- flutter - 在颤动中更新页面上的数据
- postgresql - 如何为 JSONB 列构建 JPA 谓词?
- javascript - Nodejs运行js报错:不能在模块外使用import语句