Vue项目解决问题

Vue 张梦琰
文章标签: Vue

1.路由重复点击报错

把下面代码加入到 src文件夹下的 router文件下 index.js 里面

//解决路由重复点击报错

const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location) {

undefined

return originalPush.call(this, location).catch(err => err)

}

Clipboard Image.png


2.解决浏览器跨域问题

使用代理API,在项目里新建一个 vue.config.js 文件把代码放进去修改地址

module.exports = {

  lintOnSave: false,

  devServer: {

    host: "localhost",

  port: 8081, // 端口号

  https: false, // https:{type:Boolean}

  open: false, //配置自动启动浏览器

  proxy: {

  '/admin': { //代理api

  target: 'http://mall.yydsn.cn/admin',//服务器api地址

  ws: true,// proxy websockets

  changeOrigin: true,//是否跨域

  pathRewrite: { //重写路径

  '^/admin': ''

  }

  }

  }

  }

}

还能输出{{restrictNumber}}个字符  
  • {{reply.author}}

    {{CommonUtil.formateDate(reply.ac_CommentDate).shortTime}}
  • 回复了{{Comments.author}} :