静态修改:

vue 在public 文件夹中有一个index.html,直接修改title中的值即可。这是最low的方法。

当然你的项目如果是使用webpack或者是vue-cli创建出来的项目,那么你会在title的地方看到

<title><%= htmlWebpackPlugin.options.title %></title>

 或者

<title><%= webpackConfig.name %></title>

以上两种写法需要在vue.config.js文件中添加代码解决;

第一种:

module.exports = {
   chainWebpack: config =>{
    config.plugin('html')
      .tap(args => {
        args[0].title = "标题";
        return args;
      })
  }
}

第二种:

module.exports = {
   configureWebpack: {
    // provide the app's title in webpack's name field, so that
    // it can be accessed in index.html to inject the correct title.
    name: name,
    resolve: {
      alias: {
        '@': resolve('src')
      }
    }
  }
}

Logo

前往低代码交流专区

更多推荐