简体   繁体   English

未被捕获的TypeError:无法将属性'innerHTML'设置为null [VueJs]

[英]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';
    }
  }
} 

To change class name: 更改班级名称:

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.

相关问题 未捕获的TypeError:无法将属性&#39;innerHTML&#39;设置为null - Uncaught TypeError: Cannot set property 'innerHTML' of null 未捕获的Typeerror:无法将属性innerHTML设置为null - Uncaught Typeerror: Cannot set property innerHTML of null 未捕获的TypeError:无法将属性&#39;innerHTML&#39;设置为null - Uncaught TypeError: Cannot set property 'innerHTML' of null 未捕获的TypeError:无法将属性&#39;innerHTML&#39;设置为null - Uncaught TypeError: Cannot set property 'innerHTML' of null 未捕获的TypeError:无法设置null的属性&#39;innerHTML&#39; - Uncaught TypeError: Cannot set property 'innerHTML' of null 未捕获的TypeError:无法在phonegap中将属性&#39;innerHTML&#39;设置为null - Uncaught TypeError: Cannot set property 'innerHTML' of null in phonegap 未捕获的TypeError:无法使用for循环将属性&#39;innerHTML&#39;设置为null - Uncaught TypeError: Cannot set property 'innerHTML' of null using a for loop 未捕获的TypeError:无法在第34行中将属性&#39;innerHTML&#39;设置为null - Uncaught TypeError: Cannot set property 'innerHTML' of null in line 34 Uncaught TypeError:无法在JS创建的div上将属性&#39;innerHTML&#39;设置为null - Uncaught TypeError: Cannot set property 'innerHTML' of null on JS created div 未捕获(承诺)TypeError:无法将属性&#39;innerHTML&#39;设置为null - Uncaught (in promise) TypeError: Cannot set property 'innerHTML' of null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM