我正在使用带有Element的Vue.js 2,并且我想使用Cleave.js进行掩蔽。
我了解如何使用数据和计算属性在Vue中创建一个基本的掩码。然而,我不想重复在Cleave中做的所有好的工作。
我还发现了vue-cleave。这似乎是将Cleave与Vue一起使用的一个好方法。尽管vue-cleave会在页面上添加一个标准的input元素。我使用的是元素,所以我需要一种使用el-input的方法。
这是大多数Vue掩码的常见问题,它们似乎向页面添加了一个标准的input元素。
那么,我的问题是:在使用Element时,集成Cleave.js的Vue方法是什么?
参考文献:
元素:http://element.eleme.io
Cleave.js:https://github.com/nosir/cleave.js
Vue-Cleave:https://github.com/vue-bulma/cleave
发布于 2017-08-18 18:13:34
我找到了这篇文章:https://vuejsdevelopers.com/2017/05/20/vue-js-safely-jquery-plugin/
它解释了如何在Vue中使用JQuery。我遵循这个模式,将Vue与Cleave集成在一起,如下所示:
SmartCleave.vue
<template>
<input />
</template>
<script>
/* eslint-disable no-new */
import Cleave from 'cleave.js'
export default {
mounted () {
new Cleave(this.$el, {
date: true,
datePattern: ['d', 'm', 'Y']
})
this.$el.oninput = (e) => {
console.log('oninput the field', e.target.value)
this.$emit('oninput', e.target.value)
}
}
}
</script>App.vue
<template>
<div id="app">
<smart-cleave @oninput="logIt"></smart-cleave>
<div>{{date}}</div>
</div>
</template>
<script>
/* eslint-disable no-new */
import Cleave from 'cleave.js'
import SmartCleave from './components/SmartCleave'
new Cleave('#plain-input', {
date: true,
datePattern: ['d', 'm', 'Y']
})
export default {
name: 'app',
components: {
SmartCleave
},
data () {
return {
date: ''
}
},
methods: {
logIt (val) {
console.log('cahnged', val)
this.date = val
}
}
}
</script>
<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
/* text-align: center; */
color: #2c3e50;
margin-top: 60px;
}
</style>https://stackoverflow.com/questions/45611073
复制相似问题