更改VueJS组件的类

时间:2018-05-23 07:31:44

标签: javascript vue.js vuejs2 vue-component

我想在2.5秒后更改VueJS中组件的类,并且我使用此代码:

const Header = {
  template: `<header :class=hclass v-html="header"></header>`,
  data () {
   return {
     hclass: 'off'
   }
  },
  methods: {
    changeVisibility () {
      window.setTimeout(function () {
        this.hclass = 'on'
        console.log('Change to on!', this.hclass)
      }, 2500)
    }
  },
  computed: {
    header () {
      this.changeVisibility()
      return store.state.header
    }
  }
}

虽然我在控制台中看到了它,然后更改为开启!&#39;,它实际上从未真正更新过我的课程,并且#39;!

1 个答案:

答案 0 :(得分:0)

感谢您指出正确的方向!

methods: {
    changeVisibility () {
        setTimeout(function () {
            this.hclass = true
            console.log('Change to on!', this.hclass)
        }.bind(this), 5000)
    }
}
相关问题