去除vue路由跳转地址栏后的哈希值#,我们只需要在路由跳转的管理文件router目录下的index.js中加上一句代码即可去掉哈希值#

mode:"history"

import Vue from 'vue'
import App from './App.vue'
// 全局导入样式【每个组件都可以用】
import "./statics/site/css/style.css"
import Vue from 'vue'
import VueRouter from 'vue-router'
import ElementUI from 'element-ui';
import axios from 'axios'
import Vuex from 'vuex'
Vue.use(Vuex)
Vue.use(ElementUI);
Vue.use(VueRouter)
import {
addLocalGoods
} from './common/localStorageTool.js'
axios.defaults.baseURL = 'http://39.108.135.214:8899/';
Vue.prototype.$axios = axios
//路由对象相关
import goodslist from './components/goods/goodslist'
import shopcart from './components/shopcart/shopcart'
import goodsinfo from './components/goods/goodsinfo'
import login from './components/account/login'
import order from './components/order/order'
import test from './components/test/test'
import 'element-ui/lib/theme-chalk/index.css';
// 使用懒加载
import VueLazyLoad from 'vue-lazyload'
import moment from 'moment'
//全局过滤器
Vue.filter('dateFmt', (input, formatString = "YYYY-MM-DD") => {
return moment(input).format(formatString)
})
const router = new VueRouter({
mode:"history",
routes: [{
path: '/',
redirect: '/goodslist'
},
{
path: '/goodslist',
component: goodslist
},
{
path: '/goodsinfo/:goodsId',
component: goodsinfo
},
{
path: '/shopcart',
component: shopcart,
meta: {
requiresAuth: true
}
},
{
path: '/login',
component: login,
},
{
path: '/order',
component: order,
},
{
path: '/test',
component: test,
},
]
}) router.beforeEach((to, from, next) => {
if (to.meta.requiresAuth == true) {
next()
} else {
next()
} })
Vue.use(VueLazyLoad, {
error: require('./statics/site/imgs/erro.jpg'),
loading: require('./statics/site/imgs/load.gif')
})
const store = new Vuex.Store({
state: {
buyCount: 0
},
getters: {
getBuyCount: state => {
return state.buyCount
}
},
mutations: {
addGoods(state, payload) {
// 变更状态
state.buyCount = addLocalGoods(payload) },
updateGoods(state, payload) {
state.buyCount = updateLocalGoods(payload)
}
}
})
/**利用Vue框架创建出来的根实例,去把根组件的template中的内容,渲染到id=app的div中去 */
new Vue({
el: "#app",
router,
store,
// render: function (createElement) {
// return createElement(App)
// }
render: h => h(App) })

去除vue路由跳转地址栏后的哈希值#的更多相关文章

  1. Vue路由跳转到新页面时 默认在页面最底部 而不是最顶部 的解决

    今天碰到一个问题   vue路由跳转到新的页面时会直接显示页面最底部  正常情况下是显示的最顶部的  而且好多路由中不是全部都是这种情况  折腾好长时间也没解决  最后在网上找到了解决办法 其实原理很 ...

  2. vue路由跳转的方式

    vue路由跳转有四种方式 1. router-link 2. this.$router.push() (函数里面调用) 3. this.$router.replace() (用法同push) 4. t ...

  3. 详解vue 路由跳转四种方式 (带参数)

    详解vue 路由跳转四种方式 (带参数):https://www.jb51.net/article/160401.htm 1.  router-link ? 1 2 3 4 5 6 7 8 9 10 ...

  4. vue路由跳转报错解决

    vue路由跳转: setTimeout(function () { console.log(this); this.$router.push("/login"); },800) 语 ...

  5. vue路由跳转取消上个页面的请求和去掉重复请求

    vue路由跳转取消上个页面的请求和去掉重复请求 axios 的二次封装(拦截重复请求.异常统一处理) axios里面拦截重复请求

  6. vue路由跳转时判断用户是否登录功能

    通过判断该用户是否登录过,如果没有登录则跳转到login登录路由,如果登录则正常跳转. 一丶首先在用户登录前后分别给出一个状态来标识此用户是否登录(建议用vuex): 简单用vuex表示一下,不会可以 ...

  7. Vue路由跳转时显示空白页面,iview的使用

    最近在用iview做项目,需要实现登录,注册,忘记密码等功能.iview-admin本来就有登录功能,于是想照葫芦画瓢,实现登录界面的注册,忘记密码页面路由跳转. router.js里路由配置,刚开始 ...

  8. vue路由跳转传参的两种方法

    路由跳转: this.$router.push({ name: '工单列表', params: {p_camera_dev_name: 'xxx'} }); 使二级菜单呈点击状态: $('[index ...

  9. vue 路由跳转前确认框,刷新浏览器页面前提示确认框

    先看效果图: 1.刷新页面效果: 2.跳转路由(进入别的页面前)效果: 代码: // 路由跳转确认 beforeRouteLeave(to, from, next) { const answer = ...

随机推荐

  1. Contiki源码结构

    Contiki源码结构 apps目录下,用于存放Application,也就是我们的应用程序放在这个目录下.如webserver,webrowser等,如下图所示. core目录是contiki操作系 ...

  2. 15 个最佳的 jQuery 布局插件【转】

    英文原文:15 Best jQuery Grid Plugins for Developers 现如今,网站开发设计的需求会要求自动适应所有移动设备,即响应式网站: 在开发网站时必须考虑对平板设备融合 ...

  3. Ajax不能接受php return值的原因

    PHP在处理ajax返回值的时候,如果使用return如 return $result会失败,echo $result却没问题.解释原因如下: 1.ajax请求从服务器端读取返回值,而且这些返回值必须 ...

  4. 002-CSS基础

    1 CSS和文档 CSS 层叠样式表 元素 每个元素都会生成一个框(box) 元素 = 替换元素 + 非替换元素 替换元素 显示的内容是元素内的某个属性而不是元素本身, 如img 非替换元素 大部分类 ...

  5. linux 多线程编程-读写者问题

    #include <cstdio> #include <pthread.h> #include <unistd.h> ]; int i,j; pthread_rwl ...

  6. uC/OS-II源码分析(六)

    μC/OS-Ⅱ总是运行进入就绪态任务中优先级最高的那一个.确定哪个任务优先级最高, 下面该哪个任务运行了的工作是由调度器(Scheduler)完成的.任务级的调度是由函数 OSSched()完成的.中 ...

  7. WPF DelegateCommand CanExecute

     private DelegateCommand searchCommand;         public DelegateCommand SearchCommand         {       ...

  8. hive 面试题

    使用 Hive或者自定义 MR 实现如下逻辑 product_no lac_id moment start_time user_id county_id staytime city_id 134291 ...

  9. matlab新手入门(三)(翻译)

    数组索引 MATLAB®中的每个变量都是一个可以容纳多个数字的数组.当您要访问阵列的选定元素时,请使用索引.例如,考虑4乘4A: A = magic(4) A =    16 2 3 13     5 ...

  10. Linux 之添加系统环境变量

    PATH 值是一系列目录,当执行命令时,linux就在这些目录下查找,其格式为: PATH=$PATH:<PATH1>:<PATH2>:<PATH3>:------ ...