How to implement currency filter in vue
This article Xiaobian for you to introduce in detail "vue how to achieve the currency filter", the content is detailed, the steps are clear, the details are handled properly, I hope this "vue how to achieve the currency filter" article can help you solve your doubts, following the editor's ideas slowly in-depth, together to learn new knowledge.
So for the component's v-model to take effect, it must:
Accept a value attribute
The input event is triggered when there is a new value
The code is as follows:
HTML:
{{message}}
Total: ${{total}}
JavaScript:
Vue.component ('currency-input', {template: `\ {label}}\ $\`, 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.jskeeper, price: 0, shipping: 0, handling: 0, discount: 0}, computed: {total: function () {return ((this.price * 100 + this.shipping * 10 + this.handling * 100-this.discount * 10) / 100) .tofixed (2)}})
The effect picture is as follows:
After reading this, the article "how to realize the currency filter in vue" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it yourself. If you want to know more about the article, please follow the industry information channel.