[英]Uncaught TypeError: Cannot set property 'innerHTML' of null [VueJs]
I see previous questions about the same problem faced me, but I try to solve it based on the solution of the questions! 我看到以前遇到的有关同一问题的问题,但我尝试根据问题的解决方案来解决! but it does not work 但它不起作用
In my <template>
: 在我的<template>
:
<modal name="MyModal" >
<span class="myClass" id="visible">visible</span>
</modal>
In my <script>
: 在我的<script>
:
export default {
name: "myProject",
data: function() {
return {}
},
methods:
Open_EditTask: function() {
this.$modal.show("MyModal");
this.CurrentTask = this.MyTask;
if ( app.EditTask.visible == true ) { document.getElementById('visible').innerHTML = 'visible'; }
else { document.getElementById('visible').innerHTML = 'hidden'; }
}
}
I used modal
plugin to create the modal. 我使用modal
插件来创建模态。
My problem is when the modal opened .. the text not changed based on the app.EditTask.variable
value, but when I try to print the value of it .. it shows me the value of it either true or false. 我的问题是模态打开时..基于app.EditTask.variable
值的文本未更改,但是当我尝试打印它的值时..它向我显示了它的值为true或false。
Error message: 错误信息:
Uncaught TypeError: Cannot set property 'innerHTML' of null 未捕获的TypeError:无法将属性'innerHTML'设置为null
Why do you not use computed, it's very easy. 为什么不使用计算机,这很简单。
Template: 模板:
<modal name="MyModal" >
<span class="myClass" id="visible"> {{ isVisible }} </span>
</modal>
Javascript: 使用Javascript:
export default {
name: "myProject",
data: function() {
return {}
},
methods:{
Open_EditTask: function() {
..
}
},
computed: {
isVisible(){
return app.EditTask.visible ? 'visible' : 'hidden';
}
}
}
Template: 模板:
<modal name="MyModal" >
<span :class="{myClass: true, hidden: !isVisible, visible: isVisible}" id="visible"></span>
</modal>
Javascript: 使用Javascript:
export default {
name: "myProject",
data: function() {
return {}
},
methods:{
Open_EditTask: function() {
..
}
},
computed: {
isVisible(){
return app.EditTask.visible;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.