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. mysql优化 - mysql count(id)查询速度如何优化?2. python - django 里自定义的 login 方法,如何使用 login_required()3. javascript - git clone 下来的项目 想在本地运行 npm run install 报错4. node.js - node_moduls太多了5. mysql主从 - 请教下mysql 主动-被动模式的双主配置 和 主从配置在应用上有什么区别?6. angular.js - 不适用其他构建工具,怎么搭建angular1项目7. 主从备份 - 跪求mysql 高可用主从方案8. android-studio - Android 动态壁纸LayoutParams问题9. python如何不改动文件的情况下修改文件的 修改日期10. 在Java中System.out.println 只能在method中使用吗?
