默认状况下,Vue项目的访问路径以 /#/,但咱们有时候可能须要给项目定义一个明确的访问路径,如 /my_vue/ 等,这时咱们须要修改配置,自定义项目的访问路径,方法以下:css

1. 在index.html添加 (pay自定义的名称)

收银台

2. 在配置路由的index.js添加 mode: ‘history’, base: ‘/pay/’

import Vue from 'vue'

import Router from 'vue-router'

import Pay from '@/components/Pay'

Vue.use(Router)

export default new Router({

mode: 'history',

base:'/pay/',

routes: [

{

path: '/',

name: 'Pay',

component: Pay

}

]

});

3. 在项目的 config\index.js配置assetsPublicPath: '/pay/',

'use strict'

const path = require('path')

module.exports = {

dev: {

// Paths

assetsSubDirectory: 'static',

assetsPublicPath: '/pay/',

proxyTable: {},

// Various Dev Server settings

host: '0.0.0.0', // can be overwritten by process.env.HOST

port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined

autoOpenBrowser: false,

errorOverlay: true,

notifyOnErrors: true,

poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-

/**

* Source Maps

*/

// https://webpack.js.org/configuration/devtool/#development

devtool: 'cheap-module-eval-source-map',

cacheBusting: true,

cssSourceMap: true

},

build: {

// Template for index.html

index: path.resolve(__dirname, '../dist/index.html'),

// Paths

assetsRoot: path.resolve(__dirname, '../dist'),

assetsSubDirectory: 'static',

assetsPublicPath: '/pay/',

/**

* Source Maps

*/

productionSourceMap: true,

devtool: '#source-map',

productionGzip: false,

productionGzipExtensions: ['js', 'css'],

bundleAnalyzerReport: process.env.npm_config_report

}

}

4. 以上就已经配置完了,最后项目的请求地址就是:

http://localhost:8080/pay/

注意: 全部的配置名称必须一致(如pay), 这样才能保证资源的正确访问html

GitHub 加速计划 / vu / vue
109
18
下载
vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
最近提交(Master分支:4 个月前 )
9e887079 [skip ci] 1 年前
73486cb5 * chore: fix link broken Signed-off-by: snoppy <michaleli@foxmail.com> * Update packages/template-compiler/README.md [skip ci] --------- Signed-off-by: snoppy <michaleli@foxmail.com> Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com> 1 年前
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐