今天碰到一个同学问了laydate在vue中的使用问题,因为以前在项目中也用过laydate,也算有一些了解,所以在这里做一个简单的测试
官方网址:http://www.layui.com/laydate/
GitHub地址:https://github.com/sentsin/laydate/
测试文件:新建vue的webpack模板
1、首先是组件里import引用
这里是在components中的hello.vue中进行
import laydate from 'layui-laydate'
export default {
name: 'hello',
data () {
return {
date: null
}
},
methods: {
getDate () {
console.log(0)
laydate.render({
elem: '#test',
done: (value) => {
this.date = value
}
})
}
}
}
效果:没有报错,点击输入框也没有反应
效果图1.png
2、在 组件中单独引入不行,那么我们来尝试一下在入口文件index.html中做常规js文件引