zoukankan      html  css  js  c++  java
  • Vue3不再支持Filters过滤器

    filters过滤器已从Vue 3.0中删除,不再支持。

    2.x 语法
    在2.x中,开发人员可以使用过滤器来处理常见的文本格式。

    <template>
    <h1>Bank Account Balance</h1>
    <p>{{ accountBalance | currencyUSD }}</p>
    </template>
    
    <script>
    export default {
    props: {
    accountBalance: {
    type: Number,
    required: true
    }
    },
    filters: {
    currencyUSD(value) {
    return '$' + value
    }
    }
    }
    </script>
    

      

      

    虽然这看起来很方便,但它需要一个自定义语法,打破大括号内表达式“只是JavaScript”的原则,这既增加了学习成本,也增加实现逻辑的成本。

    3.x 更新
    在3.x中,过滤器被删除,不再受支持。相反,我们建议用方法调用或计算属性替换它们。

    下面的例子是一个实现类似功能的。

    <template>
    <h1>Bank Account Balance</h1>
    <p>{{ accountInUSD }}</p>
    </template>
    
    <script>
    export default {
    props: {
    accountBalance: {
    type: Number,
    required: true
    }
    },
    computed: {
    accountInUSD() {
    return '$' + this.accountBalance
    }
    }
    }
    </script>
    

      

    官方建议用计算属性或方法代替过滤器,而不是使用过滤器。

  • 相关阅读:
    Excel—TIME函数简介与用法
    Excel—LEFT、RIGHT、MID函数提取不同位置的字段
    $scope.triggerSave $scope.createForm.dayType.$dirty = false;
    SVN clean up的作用
    js 获取当年到今日的时间区间
    jersey
    vector
    AngularJS 2
    URL 字符介绍
    JS factory
  • 原文地址:https://www.cnblogs.com/ygunoil/p/15772648.html
Copyright © 2011-2022 走看看