我发现这篇文章:https://vuejsdevelopers.com/2017/05/20/vue-js-safely-jquery-plugin/
这解释了如何使用JQuery与Vue。我跟着这个模式和集成的Vue公司与顺劈斩如下:
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>