javascript - vue中如何使用mobiscroll插件
问题描述
项目中需要将以前的jquery换成vue实现,之前的代码使用mobiscroll实现的,现在把之前的插件js都放在了index.html下面了,但是在首页却总是报Error in mounted hook: 'ReferenceError: mobiscroll is not defined'。是该插件不支持vue吗?总是报mobiscroll这个方法不存在,我用webstrom确实能点到插件里面的,所以依赖不是问题。js插件是放在index.html下引入的,没有用npm报错代码是:initPage(){
var currYear = (new Date()).getFullYear();mobiscroll.settings$(’#dataTime’).mobiscroll().date({ theme : 'android-holo', mode : 'scroller', display : 'bottom', lang : 'zh', dateFormat : ’yyyy-mm-dd’, defaultValue : new Date(new Date().setFullYear(currYear - 30)), startYear : currYear - 70, endYear : currYear + 10});$('.checkbox-span').click(function() { var idname = $(this).attr('id'); console.log(idname) if (idname == 'xz-checkbox') { $(this).removeAttr('id'); $('.main-btn').attr('disabled', 'disabled'); $('.main-btn').css('background', '#CCCCCC'); } else { $(this).attr('id', 'xz-checkbox'); $('.main-btn').removeAttr('disabled'); $('.main-btn').css('background', ''); }})$('.radio-p').click(function() { $('.radio-p').removeAttr('id'); $('.radio-span').html(''); $(this).attr('id', 'xz-radio-p'); $(this).children('.radio-span').html('<span></span>') $('#userinfo').find('input[name=’sex’]').val($(this).data('sex'));}) },
问题解答
回答1:npm install exports-loader //下载webpack loader插件
将mobiscroll插件(包括css)放在common下的js文件夹中
在需要调用Mobiscroll的组件中调用
require(’exports?$=jQuery!../../Common/js/mobiscroll.js’)
相关文章:
1. python - 请问用cxfreeze打包的可执行程序能反编译出源码么?2. javascript - 这种上传图片预览怎么做?3. javascript - prismplayer播放器全屏问题4. javascript - vue2.0中router.repalce跟router.push有什么区别,二者的应用场景是会有怎样的区别?5. javascript - js判断一个数组是否重复6. javascript - input输入框触发change事件后,外部元素会被选中7. python - 用__call__ 实现装饰器功能8. javascript - 把字符串日期转换成一般时间格式后,发现小于10的数字不会自动添加0在前面,如下9. python相关问题求解决,有偿10. javascript - 在sublime中如何给.vue文件注释?