javascript - vue中如何使用mobiscroll插件
問題描述
項(xiàng)目中需要將以前的jquery換成vue實(shí)現(xiàn),之前的代碼使用mobiscroll實(shí)現(xiàn)的,現(xiàn)在把之前的插件js都放在了index.html下面了,但是在首頁卻總是報(bào)Error in mounted hook: 'ReferenceError: mobiscroll is not defined'。是該插件不支持vue嗎?總是報(bào)mobiscroll這個(gè)方法不存在,我用webstrom確實(shí)能點(diǎn)到插件里面的,所以依賴不是問題。js插件是放在index.html下引入的,沒有用npm報(bào)錯(cuò)代碼是: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文件夾中
在需要調(diào)用Mobiscroll的組件中調(diào)用
require(’exports?$=jQuery!../../Common/js/mobiscroll.js’)
相關(guān)文章:
1. mysql儲(chǔ)存json錯(cuò)誤2. 在mybatis使用mysql的ON DUPLICATE KEY UPDATE語法實(shí)現(xiàn)存在即更新應(yīng)該使用哪個(gè)標(biāo)簽?3. 哭遼 求大佬解答 控制器的join方法怎么轉(zhuǎn)模型方法4. 怎么php怎么通過數(shù)組顯示sql查詢結(jié)果呢,查詢結(jié)果有多條,如圖。5. sql語句 - 如何在mysql中批量添加用戶?6. mysql - 表名稱前綴到底有啥用?7. mysql - 怎么生成這個(gè)sql表?8. Navicat for mysql 中以json格式儲(chǔ)存的數(shù)據(jù)存在大量反斜杠,如何去除?9. 編輯成功不顯示彈窗10. mysql - 數(shù)據(jù)庫表中,兩個(gè)表互為外鍵參考如何解決
