vue踩坑之在input中使用filters局部過濾器問題
在input中使用filters局部過濾器
? 最近在項目中遇到需要對Input框中v-model綁定的枚舉值進行過濾展示到頁面上,萬事具備,刷新頁面后發(fā)現(xiàn)filters并沒有起作用
控制臺還報錯:
[Vue warn]: Property or method "filterTime" is not defined on the instance but referenced during render.
Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.
于是乎,我就重新研究了一下vue.js的過濾器filters
,發(fā)現(xiàn)filters只能用在兩個地方:雙花括號插值和 v-bind
表達(dá)式 (后者從 2.1.0+ 開始支持)。
中文官網(wǎng)鏈接:https://cn.vuejs.org/v2/guide/filters.html
解決方案
使用計算屬性
? 一個小demo:
<template> <input v-model="filterCardType" placeholder="證件類型" /> </template> <script> export default { data() { return { agent_detail: { agent_detail:1, }, }; }, computed:{ "filterCardType"(){ if(this.agent_detail.cardType==0){ return "二代身份證" }else if(this.agent_detail.cardType==1){ return "護照" }else if(this.agent_detail.cardType==2){ return "港澳通行證" }else if(this.agent_detail.cardType==3){ return "臺灣通行證" }else if(this.agent_detail.cardType==4){ return "香港永久性居民身份證" }else if(this.agent_detail.cardType==5){ return "軍官證" } } } } </script>
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
vuex提交state&&實時監(jiān)聽state數(shù)據(jù)的改變方法
今天小編就為大家分享一篇vuex提交state&&實時監(jiān)聽state數(shù)據(jù)的改變方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09vue-loader和webpack項目配置及npm錯誤問題的解決
這篇文章主要介紹了vue-loader和webpack項目配置及npm錯誤問題的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-07-07Vue中關(guān)于異步請求數(shù)據(jù)未更新的解決
本文將探討Vue中異步請求數(shù)據(jù)未更新的常見原因,并提供解決方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2025-03-03