您现在的位置是:网站首页> 编程资料编程资料
vue路径上如何设置指定的前缀_vue.js_
2023-05-24
442人已围观
简介 vue路径上如何设置指定的前缀_vue.js_
vue路径上设置指定的前缀
有时在使用项目的时候,我们都需要指定一个前缀路径(就像tomcat中的虚拟路径),这个时候在vue中如何使用呢。
解决
这个时候我们可以使用vue-router中的base这个属性,使用这个属性就可以在路径前面添加指定的前缀。
export default new Router({ mode: 'history', //后端支持可开 # base: '/wtlicence', scrollBehavior: () => ({ y: 0 }), routes: constantRouterMap });这个时候的访问路径是: http://127.0.0.1:8080/login.
当我们使用vue-router的base属性的时候。
export default new Router({ mode: 'history', //后端支持可开 base: '/wtlicence', scrollBehavior: () => ({ y: 0 }), routes: constantRouterMap });这个时候的访问路径是: http://127.0.0.1:8080/wtlicence/login
vue history模式、前缀
路由history模式
router/index.js
mode: 'history', base: '/sss', // 路由前缀

路由前缀
config/index.js
开发dev和线上build配置中,将static改成想要的前缀。


assetsSubDirectory: 打包后的静态资源要存放的路径(static)
最后,改成history模式后部署, 刷新会有问题。需要更改服务器配置(config)
server{ listen 8888; server_name localhost; root html location / { try_files $uri $uri/ @router; index index.html index.htm; } location @router { rewrite ^.*$ /index.html last; } }新增的主要是:
location / { try_files $uri KaTeX parse error: Expected 'EOF', got '}' at position 51: …l index.htm; }̲ location @rou… /index.html last; }以上为个人经验,希望能给大家一个参考,也希望大家多多支持。
相关内容
- 详解React hooks组件通信方法_React_
- vue对插件(iview,elementui,treeselect)样式的局部修改方式_vue.js_
- Vue动态构建混合数据Treeselect选择树及巨树问题的解决_vue.js_
- vue-treeselect显示unknown的问题及解决_vue.js_
- VueTreeselect 参数options的数据转换-参数normalizer解析_vue.js_
- 关于vue-lunar-full-calendar的使用说明_vue.js_
- 小程序实现简单验证码倒计时_javascript技巧_
- 微信小程序转盘抽奖的实现方法_javascript技巧_
- vuex store 缓存存储原理分析_vue.js_
- vue对象添加属性(key:value)、显示和删除属性方式_vue.js_
