webpack引用路徑出錯了嗎?
在別的js中引入'use?strict'; var?_mm?=?require('util/mm.js');
編寫的_mm的模塊'use strict';
var _mm = {
// 網絡請求
? request : function(param){
? var _this = this;
? ? ?$.ajax({
? ? ? ? type ? ? : param.method || 'get',
? ? ? ?url ? ? ?: param.url ? ?|| ?'',?
? ? ? ? dataType : param.type ? || 'json',
? ? ? ? data ? ? : param.data ? || '',
? ? ? ? success ?: function(res){
? ? ? ? // 請求成功
? ? ? ? ? ? ? if(0 === res.status){
? ? ? ? ? ? ? typeof param.success === 'function' && param.success(res.data,res.msg);
? ? ? ? ? ? ? }
? ? ? ? ? ? ? // 沒有登錄狀態(tài),需要強制登錄
? ? ? ? ? ? ? else if(10 === res.status){
? ? ? ? ? ? ? ? ? ?_this.doLogin();
? ? ? ? ? ? ? }
? ? ? ? ? ? ? // 請求數據錯誤
? ? ? ? ? ? ? else if(1 === res.status){
? ? ? ? ? ? ? ? typeof param.error === 'function' && param.error(res.msg);
? ? ? ? ? ? ? }
? ? ? ? },
? ? ? ? error ? ?: function(err){
? ? ? ? ? typeof param.error === 'function' && param.error(err.statusText);
? ? ? ? }
? ? ?});
? },
? //統(tǒng)一登錄處理
? doLogin : function(){
? window.location.href = './login.html?redirect=' + encodeURIComponent(window.location.href);
? }
};
module.exports = _mm;
總是報這樣的錯誤
2017-08-16
webpack.config.js中要給util文件夾配置別名
resolve: {
? ?alias: {
? ? ? ?util: __dirname + '/src/util'
? ?}
}