国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > WEB開發 > 正文

vue實現貨幣過濾器

2024-04-27 15:13:25
字體:
來源:轉載
供稿:網友

自定義事件也可以用來創建自定義的表單輸入組件,使用 v-model 來進行數據雙向綁定。

所以要讓組件的 v-model 生效,它必須:

接受一個 value 屬性在有新的 value 時觸發 input 事件代碼如下:HTML:<div id="app">  <p>{{ message }}</p>    <currency-input label="PRice" v-model="price"></currency-input>  <currency-input label="Shipping" v-model="shipping"></currency-input>  <currency-input label="Handling" v-model="handling"></currency-input>  <currency-input label="Discount" v-model="discount"></currency-input>  <p>Total: ${{ total }}</p></div>javaScript:Vue.component('currency-input', {  template: `/  <div>/    <label v-if="label">{{ label }}</label>/      $/      <input/      ref="input"/        v-bind:value="value"/        v-on:input="updateValue($event.target.value)"/        v-on:focus="selectAll"/        v-on:blur="formatValue"/       >/      </div>/  `,  props: {  value: {    type: Number,      default: 0    },    label: {    type: String,      default: ''    }  },  mounted: function () {  this.formatValue()  },  methods: {    updateValue: function (value) {    var result = currencyValidator.parse(value, this.value)      if (result.warning) {      this.$refs.input.value = result.value      }      this.$emit('input', result.value)    },    formatValue: function () {    this.$refs.input.value = currencyValidator.format(this.value)    },    selectAll: function (event) {    setTimeout(function () {      event.target.select()      }, 0)    }  }})new Vue({  el: '#app',  data: {    message: 'Hello Vue.js!',    price: 0,    shipping: 0,    handling: 0,    discount: 0  },  computed: {  total: function () {    return ((      this.price * 100 +        this.shipping * 100 +        this.handling * 100 -        this.discount * 10      ) / 100).toFixed(2)    }  }})效果圖如下:

每個 Vue 實例都實現了事件接口(Events interface),即:

使用 $on(eventName) 監聽事件使用 $emit(eventName) 觸發事件v-model實現雙向傳遞。
上一篇:我的ionic配置

下一篇:css偽類的順序

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 从江县| 东城区| 时尚| 襄汾县| 宁城县| 陆良县| 永春县| 沂源县| 无棣县| 虎林市| 龙胜| 百色市| 漳平市| 监利县| 博客| 赣榆县| 陆丰市| 布尔津县| 双峰县| 乌什县| 藁城市| 陈巴尔虎旗| 临江市| 淮安市| 大厂| 波密县| 略阳县| 通江县| 淮阳县| 崇仁县| 汾阳市| 拉萨市| 友谊县| 壶关县| 理塘县| 泸水县| 宕昌县| 通道| 乾安县| 西青区| 呼伦贝尔市|