简体   繁体   English

Vue JS计算属性和jquery

[英]Vue JS computed property and jquery

I want to turn an element invisible when a (bootstrap) tab is active. 我想在(引导程序)选项卡处于活动状态时将元素变为不可见。

So, the way I'm trying to do it is creating a computed property that returns if the tab is active using jquery this way: 所以,我试图这样做的方法是创建一个计算属性,如果使用jquery以这种方式激活选项卡,则返回:

computed: {
    IsAbainteracoesAtiva: function () {
        return ($('div.active')[1].id == "interacoes")
    }
}

But this computed property always returns false, even if it's true. 但是这个计算属性总是返回false,即使它是真的。 My guess is that Vue is not updating it. 我的猜测是Vue没有更新它。

Any sugestions? 任何sugestions? I'm opened to other solutions too. 我也接受了其他解决方案。

I assume the bootstrap tap is active with a click, otherwise correct me, and I'll come back with another answer. 我假设自动点击是活动的,点击,否则纠正我,我会回来另一个答案。

// Simulate tab
<tab @click="toggleTabState"></tab>

// Simulate bootstrap element to show
<div v-if="tabIsOpen"></div>

export default {
  data() {
    return {
      tabIsOpen: false
    }
  },

  methods: {
    toggleTabState() {
      this.tabIsOpen = !this.tabIsOpen
    }
  }
}

Gonna need some of your HTML to see what else is going on. 需要你的一些HTML来看看还有什么。 Are you iterating through a lot of elements with a v-for ? 你是否用v-for迭代了很多元素?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM