• 去除vue路由跳转地址栏后的哈希值#


    去除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)
    
    })
  • 相关阅读:
    三剑客之Grep家族
    Linux默认权限命令:umask
    Linux特殊权限管理SUID|SGID|STICKY
    zabbix的web界面出现乱码解决方案
    启动zabbix-server/agent报错:cannot open "/etc/zabbix/logs/zabbix_server.log": [13] Permission denied
    Zabbix-Agent配置文件详解
    使用yum安装报错:[Errno 256] No more mirrors to try
    grep/sed/awk命令查看指定时间段的日志
    数据库SQL练习(一):数据查询
    连接数据库报错:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
  • 原文地址:https://www.cnblogs.com/DZzzz/p/8964414.html
Copyright © 2020-2023  润新知