您的位置:首页技术文章
文章详情页

javascript - vue中如何使用mobiscroll插件

【字号: 日期:2023-04-06 09:04:35浏览:63作者:猪猪

问题描述

项目中需要将以前的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’)

标签: JavaScript
相关文章: