<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script src="https://unpkg.com/vue@2.5.16/dist/vue.js"></script>
<div id="app">
<input type="text" v-model="available_time" v-format-floor>
<input type="text" v-model="a" v-format-floor>
<button @click="show">button</button>
</div>
<script>
var vm = new Vue({
el:"#app",
data:{
available_time:"",
a: '',
},
methods:{
show(){
console.log(this.a)
}
},
directives: { "format-floor": {
update: function (e,vnode,oldVnode) {
// 获取变量名字
var temp = oldVnode.data.directives[0].expression;var e = e.value;
e = Math.floor(e) || 0;
vm[temp] = e;
}
}
}
})
</script>
</body>
</html>