简体   繁体   English

Vue.js v-show 指令反应性

[英]Vue.js v-show directive reactivity

I have a div with a v-show and a v-for directive rending into my template.我有一个带有v-showv-for指令的 div 渲染到我的模板中。

Since I need to show/hide per index key, I am passing the index inside the v-show function, which forces me to write aa method function, rather than a computed function.由于我需要显示/隐藏每个索引键,我在v-show function 中传递索引,这迫使我编写一个方法 function,而不是计算出的 ZC1C425268E68385D1AB5074C1。

My question is that at a certain point, I would like to use Vue to show the hidden divs reactively, without re-rendering, how would I accomplish that?我的问题是,在某个时候,我想使用 Vue 来响应式地显示隐藏的 div,而无需重新渲染,我将如何实现呢?

Template模板

<div
    v-for="(file,index) in cluster.files"
    v-show="showPartialFiles(index)"
    v-bind:key="index"
>

Script脚本

methods: {
            showPartialFiles: function(index){
                if (index <= this.$store.state.numberOfAssignmentCutoff - 1)
                return true;
            },
    }

ps I have no problem writing in vanilla/JQuery to accomplish this yet I want to build this with Vue into the Vue object for extensibility and reusability in the future. ps 我用 vanilla/JQuery 编写来完成这个没有问题,但我想用 Vue 将它构建到 Vue object 中,以便在未来实现可扩展性和可重用性。

Many thanks, Bud.非常感谢,巴德。

You can use a computed property for that, then the v-show will react to changes in the store;您可以为此使用计算属性,然后 v-show 将对商店中的更改做出反应;

computed: {
    showPartialFiles() {
        return (index) => {
            return index <= this.$store.state.numberOfAssignmentCutoff - 1
        }
    }
}

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

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