在vue路由模式中添加favicon.ico語普通頁面不同,僅僅在header中添加是沒有效果的。
1、首先將favicon.ico圖片放在根目錄下

2、修改webpack配置文件
(1)找到build下的webpack.dev.conf.js文件
在plugins:[]下加入:
new HtmlWebpackPlugin({ filename: 'index.html', template: 'index.html', inject: true, favicon: path.resolve('favicon.ico') }),
(2)找到build下的webpack.prod.conf.js文件
同樣的在在plugins:[]下加入:
new HtmlWebpackPlugin({ filename: process.env.NODE_ENV === 'testing' ? 'index.html' : config.build.index, template: 'index.html', inject: true, favicon: path.resolve('favicon.ico'), minify: { removeComments: true, collapseWhitespace: true, removeAttributeQuotes: true // more options: // https://github.com/kangax/html-minifier#options-quick-reference }, // necessary to consistently work with multiple chunks via CommonsChunkPlugin chunksSortMode: 'dependency' }),
修改配置文件后需重啟npm run dev ,
打包后,可以看到根目錄下多了一個網頁icon。

