VueJs过滤器无效

时间:2019-06-18 03:56:11

标签: javascript vue.js vuejs2

简单的代码示例

a[0] == '\xf2'

我正在尝试应用一个简单的过滤器<!DOCTYPE html> <html> <head> <title>My first Vue app</title> <script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.0/axios.min.js"></script> <style> </style> </head> <body> <div id="app"> <h1>Bitcoin Price Index</h1> <div v-for="currency in info"> {{ currency.description }} <span v-html="currency.symbol"></span>{{ currency.rate_float || currencyToDeciaml }} </div> </div> <script> const app = new Vue({ el : '#app', data : { info : null, }, filters : { currencyToDeciaml(val) {console.log(`foo`); return Number(val).toFixed(2); } }, // Dom is ready so now load the data mounted() { axios.get(`https://api.coindesk.com/v1/bpi/currentprice.json`) .then(response => this.info = response.data.bpi); }, }); </script> </body> </html>,但是它甚至没有被执行,并且currencyToDeciaml不会显示。我似乎无法弄清楚。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:4)

过滤器的正确语法是:

{{ currency.rate_float | currencyToDeciaml }}

只有一个管道