首页 > 解决方案 > vue中未定义的testCategories

问题描述

当我加载我的页面时,我的测试类别未定义。如果我在 vue 的挂载部分执行此操作,console.log(this.testCategories);那么我会得到一个类别数组,但如果我对我的过滤器部分执行此操作,它会给我未定义。

我不明白为什么会这样。

这是我的代码

<template>
    <div>
        <div class="card mb-4" style="width: 100%;">
            <div class="card-body">
                <td>{{test.category | testCategory}}</td>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        props: ['testCategories'],
        data() {
            return {

            }
        },
        mounted() {

        },
        computed: {

        },
        methods: {

        },
        filters: {
            testCategory(value) {
                console.log('testCategories', this.testCategories);
            }
        },
    }
</script>

标签: vue.jsvuejs2

解决方案


您需要将您的属性更改为test,它有一个成员category。或者参考声明的属性testCategories

 <theComponent :test='{category:"foobar"}' :testCategory='foobar' />
{
       props: ['test', 'testCategory'],
      
}


推荐阅读