javascript - 为什么我的按钮不使用方法更改内部文本?
问题描述
我尝试使用一种方法,在单击编辑按钮后将其内部文本更改为保存,但它似乎不起作用。我需要一点帮助。
b-button.editbtn.d-flex.flex-row.mb-3(@click="editBlood")
p.mb-0.text-white.p-1#editbtns Edit
editBlood() {
this.edit = !this.edit
if(this.edit == !this.edit) {
document.getElementById('editbtns').text = "Save";
}
else {
document.getElementById('editbtns').text = "Edit";
}
解决方案
声明一个本地道具并将文本存储在那里,而不是尝试重新定位元素以设置其 innerText 道具。
<template>
<button @click="editBlood">{{ text }}</button>
</template>
<script>
var app = new Vue({
el: '#app',
data: {
button: {
text: 'My button text'
},
},
methods: {
editBlood: function() {
this.button.text = "new text!";
},
}
</script>
推荐阅读
- python - 在 python 中使用日期和时间存储 OHLC 数据
- python-3.x - Python session.get 响应使用“latin-1”而不是“utf-8”编码
- jquery - Jquery Mobile:listview 远程自动完成官方演示不起作用
- c++ - gtkmm 多点触控设备无法识别 (Windows)
- powerbi - PowerBI:使用表中各个列的 SelectedValue 创建表
- javascript - Angular + Firebase - 组件在页面刷新时不保持身份验证状态
- flutter - 无法使用 HttpClient 从 Flutter Web 发布
- reactjs - Promise.all 错误 - 类型 '(Video | undefined)[]' 不可分配给类型 'Video[]'
- python - UnicodeEncodeError:“latin-1”编解码器无法在位置 14 编码字符“\u2013”:序数不在范围内(256)
- cpu - 当指令间的取指周期不同时,如何知道控制信号?