美文网首页
vue计算属性

vue计算属性

作者: 程序猿的小生活 | 来源:发表于2022-12-30 09:40 被阅读0次

1.只读

<template>
    <div :style="aa">
        {{test}}
    </div>
</template>

<script>

    export default {
computed: {
            test(){
                return this.h
            }
        },
}

2.可修改 通过set

<template>
    <div :style="aa">
        {{test}}
    </div>
</template>

<script>

    export default {
methods: {
            ck() {
                this.test = "已修改” //修改this.h的值

            },
computed: {
        test:{
                get(){
                    return this.h
                },
                set(newValue){//修改属性值
                this.h= newValue
                }
            }       },
}

相关文章

网友评论

      本文标题:vue计算属性

      本文链接:https://www.haomeiwen.com/subject/eehtcdtx.html