_mm.getServerUrl is not a function
来源:4-11 通用侧边导航开发
jioqq237
2018-11-13
其他文件在下面回复里,已经找了一天了不知道问题在哪。。
我的index.string:
写回答
4回答
-
Rosen
2018-11-13
文件里引入 mm.js 了么?应该是低级错误,找不到的话代码打包发我吧
012018-11-15 -
jioqq237
提问者
2018-11-13
//layout/index.html <!DOCTYPE html> <html> <head> <%= require('html-loader!./layout/head-common.html') %> <title>Happymmall电商平台</title> </head> <body> <%= require('html-loader!./layout/nav.html') %> <%= require('html-loader!./layout/header.html') %> <div class="page-wrap w"> <%= require('html-loader!./layout/nav-side.html') %> <div class="content with-nav">test</div> </div> <%= require('html-loader!./layout/footer.html') %> </body> </html>
00 -
jioqq237
提问者
2018-11-13
//mm.js文件 'use strict'; var Hogan = require('hogan.js'); var conf = { serverHost : '' }; 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); } // 没有登陆状态,需要强制登陆 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); } }); }, // 获取服务器地址 getServerUrl : function(path){ return conf.serverHost + path; }, getUrlParam :function(name){ var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)'); var result = window.location.search.substr(1).match(reg); return result ? decodeURIComponent(result[2]) : null; }, //渲染html模板 renderHtml : function(htmlTemplate, data){ var template = Hogan.compile(htmlTemplate), result = template.render(data); return result; }, // 成功提示 successTips : function(msg){ alert(msg || '成功'); }, errorTips : function(msg){ alert(msg || '哪里不对了'); }, // 字段的验证,支持非空,手机,邮箱的判断 validate : function(value, type){ var value = $.trim(value); if('require' === type){ return !!value; } if ('phone' === type) { return /^1d{10}$/.test(value); } if ('email' === type) { return /^(w)+(.w+)*@(w)+((.w{2,3}){1,3})$/.test(value); } }, // 统一登陆处理 doLogin : function(){ window.location.href = './user-login.html?redirect' + encodeURIComponent(window.location.href) }, goHome : function(){ window.location.href = './index.html'; } } module.exports = _mm;`
00 -
jioqq237
提问者
2018-11-13
//webpack.config.js文件 var webpack = require('webpack'); var ExtractTextPlugin = require('extract-text-webpack-plugin'); var HtmlWebpackPlugin = require('html-webpack-plugin'); // 环境变量配置,dev / online var WEBPACK_ENV = process.env.WEBPACK_ENV || 'dev'; // 获取html-webpack-plugin参数的方法 var getHtmlConfig = function(name){ return{ template : './src/view/'+ name +'.html', filename : 'view/'+ name +'.html', inject : true, hash : true, chunks : ['common',name] } } var config = { entry:{ 'common': ['./src/page/common/index.js','webpack-dev-server/client?http://localhost:8088/'], 'index' : ['./src/page/index/index.js'], 'login' : ['./src/page/login/index.js'], 'result': ['./src/page/result/index.js'], }, output:{ path:__dirname+'/dist/', publicPath : '/dist', filename:'js/[name].js' }, externals:{ 'jquery':'window.jQuery' }, module:{ loaders:[ { test:/\.css$/, loader:ExtractTextPlugin.extract("style-loader","css-loader") }, { test: /\.(gif|jpg|png|woff|svg|eot|ttf)\??.*$/, loader: 'url-loader?limit=20000&name=resource/[name].[ext]'}, { test:/\.string$/, loader: 'html-loader'} ] }, resolve : { alias :{ node_modules: __dirname + '/node_modules', util : __dirname + '/src/util', page : __dirname + '/src/page', service : __dirname + '/src/service', image : __dirname + '/src/image', view : __dirname + '/src/view' } }, plugins: [ //独立通用模块到js/base.js new webpack.optimize.CommonsChunkPlugin({ name: 'common', filename: 'js/base.js' }), //把css单独打包到文件里 new ExtractTextPlugin("css/[name].css"), //html模板的处理 new HtmlWebpackPlugin(getHtmlConfig('index')), new HtmlWebpackPlugin(getHtmlConfig('login')), new HtmlWebpackPlugin(getHtmlConfig('result')), ] }; if('dev' === WEBPACK_ENV){ config.entry.common.push('webpack-dev-server/client?http://localhost:8088/') } module.exports = config;
00
相似问题