繁体   English   中英

如何在计算属性中获取插槽道具?

[英]How to get slot props in computed property?

我想在计算属性中获取插槽道具。 目前我将插槽道具传递给一个方法并且它工作正常。 但我想使用v-model 我可以这样做吗?

// MediaSelect.vue
<template>
    <input-wrapper v-slot="slotProps">
        <gallery-list 
            :value="getValue(slotProps.language)" // current
            v-model="myValue" // I want
        >
        </gallery-list>
    </input-wrapper>
</template>

<script>
    export default {
        computed: function(){
            myValue: {
                set: function(value){
                    this.$emit("input", value);
                },
                get: function(){
                    // I want to get slotProps in here, like this
                    return this.getValue(this.slotProps.language)
                }
                
            }
            
        },
        methods: {
            getValue: function(language){
                ...
            },
        }
    }
</script>

不,这是不可能的,您不能将参数传递给计算属性(这就是方法的用途)。

你应该这样做:

<input-wrapper v-slot="slotProps">
  <gallery-list 
    :value="getValue(slotProps.language)"
    @input="$emit('input', $event)"
  >
  </gallery-list>
</input-wrapper>

暂无
暂无

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

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