console
Vue.config.productionTip = false
Vue.config.devtools = false
Vue.component('calculate-input', {
template: "#calculate-input-temp",
props: {
'value':{
type:Number,
default: 0,
required: true
},
label: {
type: String,
default: '',
required: true
}
},
methods: {
updateValue (val) {
var formatValue = val.trim().slice(0, val.indexOf('.') + 3)
if (formatValue !== val) {
this.$refs.input.value = formatValue
}
this.$emit('input', Number(formatValue))
},
selectAll (event) {
},
formatValue() {
},
test () {
alert(1)
}
}
})
new Vue({
el: "#app",
data: {
price: 0
},
computed: {
total(){
return this.price*10;
}
},
methods: {
test1(message, event){
console.log(message)
},
test2(){
console.log("this is test2")
}
}
})
function alertSomething(a){
alert(a)
}
<div id="app">
<calculate-input label="Price" v-model="price" :test="test1('123')"></calculate-input>
<br />
{{ total }}
</div>
<template id="calculate-input-temp">
<div class="calculate-input">
<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"
>
<button v-on:click="$emit('test1')">23e</button>
</div>
</template>