vue-cli webpack配置文件分析
相信vue使用者對(duì)vue-cli都不會(huì)陌生,甚至可以說,很熟悉了,但對(duì)其webpack的配置可能知之甚少吧。
過完年回來后,我接手了公司的新項(xiàng)目。新項(xiàng)目是一個(gè)spa。很自然,我就想到了vue-cli腳手架了,當(dāng)時(shí)研究一下它的webpack配置。于是,就有了其他的內(nèi)容。
今天這篇文章,是在原來的基礎(chǔ)上,增加了一些新版本的內(nèi)容,但實(shí)質(zhì)上變化不大。
說明
此倉庫為vue-cli webpack的配置分析,其實(shí)只是在源碼中加上注釋而已。大家查看詳細(xì)分析,可以從后面提到的入口文件開始查看。
分析不包括check-versions.js文件,因?yàn)閏heck-versions.js是檢測(cè)npm和node版本,不涉及webpack,所以就沒有對(duì)check-versions.js進(jìn)行分析。同時(shí),也不包括測(cè)試部分的代碼,該分析只是針對(duì)開發(fā)和生產(chǎn)環(huán)境的webpack配置進(jìn)行分析。
vue-cli 版本
2.8.1
入口
從package.json可以看到開發(fā)和生產(chǎn)環(huán)境的入口。
"scripts": { "dev": "node build/dev-server.js", "build": "node build/build.js" }
開發(fā)環(huán)境
開發(fā)環(huán)境的入口文件是 build/dev-server.js。
dev-server.js
該文件中,使用express作為后端框架,結(jié)合一些關(guān)于webpack的中間件,搭建了一個(gè)開發(fā)環(huán)境。
// 配置文件 var config = require('../config') // 如果 Node 的環(huán)境無法判斷當(dāng)前是 dev / product 環(huán)境 // 使用 config.dev.env.NODE_ENV 作為當(dāng)前的環(huán)境 if (!process.env.NODE_ENV) { process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV) } // 可以強(qiáng)制打開瀏覽器并跳轉(zhuǎn)到指定 url 的插件 // https://github.com/sindresorhus/opn var opn = require('opn') // node自帶的文件路徑工具 var path = require('path') // express框架 var express = require('express') var webpack = require('webpack') // 測(cè)試環(huán)境,使用的配置與生產(chǎn)環(huán)境的配置一樣 // 非測(cè)試環(huán)境,即為開發(fā)環(huán)境,因?yàn)榇宋募挥袦y(cè)試環(huán)境和開發(fā)環(huán)境使用 var proxyMiddleware = require('http-proxy-middleware') var webpackConfig = process.env.NODE_ENV === 'testing' // 生產(chǎn)環(huán)境配置文件 ? require('./webpack.prod.conf') // 開發(fā)環(huán)境配置文件 : require('./webpack.dev.conf') // 端口號(hào)為命令行輸入的PORT參數(shù)或者配置文件中的默認(rèn)值 var port = process.env.PORT || config.dev.port // 配置文件中 是否自動(dòng)打開瀏覽器 var autoOpenBrowser = !!config.dev.autoOpenBrowser // 配置文件中 http代理配置 // https://github.com/chimurai/http-proxy-middleware var proxyTable = config.dev.proxyTable // 啟動(dòng) express 服務(wù) var app = express() // 啟動(dòng) webpack 編譯 var compiler = webpack(webpackConfig) // 可以將編譯后的文件暫存到內(nèi)存中的插件 // https://github.com/webpack/webpack-dev-middleware var devMiddleware = require('webpack-dev-middleware')(compiler, { // 公共路徑,與webpack的publicPath一樣 publicPath: webpackConfig.output.publicPath, // 不打印 quiet: true }) // Hot-reload 熱重載插件 // https://github.com/glenjamin/webpack-hot-middleware var hotMiddleware = require('webpack-hot-middleware')(compiler, { log: () => {} }) // 當(dāng)tml-webpack-plugin template更改之后,強(qiáng)制刷新瀏覽器 compiler.plugin('compilation', function (compilation) { compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) { hotMiddleware.publish({ action: 'reload' }) cb() }) }) // 將 proxyTable 中的請(qǐng)求配置掛在到啟動(dòng)的 express 服務(wù)上 Object.keys(proxyTable).forEach(function (context) { var options = proxyTable[context] // 如果options的數(shù)據(jù)類型為string,則表示只設(shè)置了url, // 所以需要將url設(shè)置為對(duì)象中的 target的值 if (typeof options === 'string') { options = { target: options } } app.use(proxyMiddleware(options.filter || context, options)) }) // 使用 connect-history-api-fallback 匹配資源 // 如果不匹配就可以重定向到指定地址 // https://github.com/bripkens/connect-history-api-fallback app.use(require('connect-history-api-fallback')()) // 將暫存到內(nèi)存中的 webpack 編譯后的文件掛在到 express 服務(wù)上 app.use(devMiddleware) // 將 Hot-reload 掛在到 express 服務(wù)上 app.use(hotMiddleware) // 拼接 static 文件夾的靜態(tài)資源路徑 var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory) // 靜態(tài)文件服務(wù) app.use(staticPath, express.static('./static')) var uri = 'http://localhost:' + port // 編譯成功后打印網(wǎng)址信息 devMiddleware.waitUntilValid(function () { console.log('> Listening at ' + uri + '\n') }) module.exports = app.listen(port, function (err) { if (err) { console.log(err) return } // 如果配置了自動(dòng)打開瀏覽器,且不是測(cè)試環(huán)境,則自動(dòng)打開瀏覽器并跳到我們的開發(fā)地址 if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') { opn(uri) } })
webpack.dev.conf.js
dev-server.js中使用了webpack.dev.conf.js文件,該文件是開發(fā)環(huán)境中webpack的配置入口。
// 工具函數(shù)集合 var utils = require('./utils') var webpack = require('webpack') // 配置文件 var config = require('../config') // webpack 配置合并插件 var merge = require('webpack-merge') // webpac基本配置 var baseWebpackConfig = require('./webpack.base.conf') // 自動(dòng)生成 html 并且注入到 .html 文件中的插件 // https://github.com/ampedandwired/html-webpack-plugin var HtmlWebpackPlugin = require('html-webpack-plugin') // webpack錯(cuò)誤信息提示插件 // https://github.com/geowarin/friendly-errors-webpack-plugin var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin') // 將 Hol-reload 熱重載的客戶端代碼添加到 webpack.base.conf 的 對(duì)應(yīng) entry 中,一起打包 Object.keys(baseWebpackConfig.entry).forEach(function(name) { baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name]) }) module.exports = merge(baseWebpackConfig, { module: { // styleLoaders rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap }) }, // 最新的配置為 cheap-module-eval-source-map,雖然 cheap-module-eval-source-map更快,但它的定位不準(zhǔn)確 // 所以,換成 eval-source-map devtool: '#eval-source-map', plugins: [ // definePlugin 接收字符串插入到代碼當(dāng)中, 所以你需要的話可以寫上 JS 的字符串 // 此處,插入適當(dāng)?shù)沫h(huán)境 // https://webpack.js.org/plugins/define-plugin/ new webpack.DefinePlugin({ 'process.env': config.dev.env }), // HotModule 插件在頁面進(jìn)行變更的時(shí)候只會(huì)重繪對(duì)應(yīng)的頁面模塊,不會(huì)重繪整個(gè) html 文件 // https://github.com/glenjamin/webpack-hot-middleware#installation--usage new webpack.HotModuleReplacementPlugin(), new webpack.NoEmitOnErrorsPlugin(), // 將 index.html 作為入口,注入 html 代碼后生成 index.html文件 // https://github.com/ampedandwired/html-webpack-plugin new HtmlWebpackPlugin({ filename: 'index.html', template: 'index.html', inject: true }), // webpack錯(cuò)誤信息提示插件 new FriendlyErrorsPlugin() ] })
webpack.base.conf.js
在webpack.dev.conf.js中出現(xiàn)webpack.base.conf.js,這個(gè)文件是開發(fā)環(huán)境和生產(chǎn)環(huán)境,甚至測(cè)試環(huán)境,這些環(huán)境的公共webpack配置??梢哉f,這個(gè)文件相當(dāng)重要。
// node自帶的文件路徑工具 var path = require('path') // 工具函數(shù)集合 var utils = require('./utils') // 配置文件 var config = require('../config') // 工具函數(shù)集合 var vueLoaderConfig = require('./vue-loader.conf') /** * 獲得絕對(duì)路徑 * @method resolve * @param {String} dir 相對(duì)于本文件的路徑 * @return {String} 絕對(duì)路徑 */ function resolve(dir) { return path.join(__dirname, '..', dir) } module.exports = { entry: { app: './src/main.js' }, output: { // 編譯輸出的靜態(tài)資源根路徑 path: config.build.assetsRoot, // 編譯輸出的文件名 filename: '[name].js', // 正式發(fā)布環(huán)境下編譯輸出的上線路徑的根路徑 publicPath: process.env.NODE_ENV === 'production' ? config.build.assetsPublicPath : config.dev.assetsPublicPath }, resolve: { // 自動(dòng)補(bǔ)全的擴(kuò)展名 extensions: ['.js', '.vue', '.json'], // 路徑別名 alias: { // 例如 import Vue from 'vue',會(huì)自動(dòng)到 'vue/dist/vue.common.js'中尋找 'vue$': 'vue/dist/vue.esm.js', '@': resolve('src'), } }, module: { rules: [{ // 審查 js 和 vue 文件 // https://github.com/MoOx/eslint-loader test: /\.(js|vue)$/, loader: 'eslint-loader', // 表示預(yù)先處理 enforce: "pre", include: [resolve('src'), resolve('test')], options: { formatter: require('eslint-friendly-formatter') } }, { // 處理 vue文件 // https://github.com/vuejs/vue-loader test: /\.vue$/, loader: 'vue-loader', options: vueLoaderConfig }, { // 編譯 js // https://github.com/babel/babel-loader test: /\.js$/, loader: 'babel-loader', include: [resolve('src'), resolve('test')] }, { // 處理圖片文件 // https://github.com/webpack-contrib/url-loader test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, loader: 'url-loader', query: { limit: 10000, name: utils.assetsPath('img/[name].[hash:7].[ext]') } }, { // 處理字體文件 test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, loader: 'url-loader', query: { limit: 10000, name: utils.assetsPath('fonts/[name].[hash:7].[ext]') } } ] } }
config/index.js
該文件在很多文件中都用到,是主要的配置文件,包含靜態(tài)文件的路徑、是否開啟sourceMap等。其中,分為兩個(gè)部分dev(開發(fā)環(huán)境的配置)和build(生產(chǎn)環(huán)境的配置)。
// 詳情見文檔:https://vuejs-templates.github.io/webpack/env.html var path = require('path') module.exports = { // production 生產(chǎn)環(huán)境 build: { // 構(gòu)建環(huán)境 env: require('./prod.env'), // 構(gòu)建輸出的index.html文件 index: path.resolve(__dirname, '../dist/index.html'), // 構(gòu)建輸出的靜態(tài)資源路徑 assetsRoot: path.resolve(__dirname, '../dist'), // 構(gòu)建輸出的二級(jí)目錄 assetsSubDirectory: 'static', // 構(gòu)建發(fā)布的根目錄,可配置為資源服務(wù)器域名或 CDN 域名 assetsPublicPath: '/', // 是否開啟 cssSourceMap productionSourceMap: true, // Gzip off by default as many popular static hosts such as // Surge or Netlify already gzip all static assets for you. // Before setting to `true`, make sure to: // npm install --save-dev compression-webpack-plugin // 默認(rèn)關(guān)閉 gzip,因?yàn)楹芏嗔餍械撵o態(tài)資源主機(jī),例如 Surge、Netlify,已經(jīng)為所有靜態(tài)資源開啟gzip productionGzip: false, // 需要使用 gzip 壓縮的文件擴(kuò)展名 productionGzipExtensions: ['js', 'css'], // Run the build command with an extra argument to // View the bundle analyzer report after build finishes: // `npm run build --report` // Set to `true` or `false` to always turn it on or off // 運(yùn)行“build”命令行時(shí),加上一個(gè)參數(shù),可以在構(gòu)建完成后參看包分析報(bào)告 // true為開啟,false為關(guān)閉 bundleAnalyzerReport: process.env.npm_config_report }, // dev 開發(fā)環(huán)境 dev: { // 構(gòu)建環(huán)境 env: require('./dev.env'), // 端口號(hào) port: 3333, // 是否自動(dòng)打開瀏覽器 autoOpenBrowser: true, assetsSubDirectory: 'static', // 編譯發(fā)布的根目錄,可配置為資源服務(wù)器域名或 CDN 域名 assetsPublicPath: '/', // proxyTable 代理的接口(可跨域) // 使用方法:https://vuejs-templates.github.io/webpack/proxy.html proxyTable: {}, // CSS Sourcemaps off by default because relative paths are "buggy" // with this option, according to the CSS-Loader README // (https://github.com/webpack/css-loader#sourcemaps) // In our experience, they generally work as expected, // just be aware of this issue when enabling this option. // 默認(rèn)情況下,關(guān)閉 CSS Sourcemaps,因?yàn)槭褂孟鄬?duì)路徑會(huì)報(bào)錯(cuò)。 // CSS-Loader README:https://github.com/webpack/css-loader#sourcemaps cssSourceMap: false } }
utils.js
utils.js也是一個(gè)被使用頻率的文件,這個(gè)文件包含了三個(gè)工具函數(shù):
- 生成靜態(tài)資源的路徑
- 生成 ExtractTextPlugin對(duì)象或loader字符串
- 生成 style-loader的配置
// node自帶的文件路徑工具 var path = require('path') // 配置文件 var config = require('../config') // 提取css的插件 // https://github.com/webpack-contrib/extract-text-webpack-plugin var ExtractTextPlugin = require('extract-text-webpack-plugin') /** * 生成靜態(tài)資源的路徑 * @method assertsPath * @param {String} _path 相對(duì)于靜態(tài)資源文件夾的文件路徑 * @return {String} 靜態(tài)資源完整路徑 */ exports.assetsPath = function (_path) { var assetsSubDirectory = process.env.NODE_ENV === 'production' ? config.build.assetsSubDirectory : config.dev.assetsSubDirectory // path.posix.join與path.join一樣,不過總是以 posix 兼容的方式交互 return path.posix.join(assetsSubDirectory, _path) } /** * 生成處理css的loaders配置 * @method cssLoaders * @param {Object} options 生成配置 * option = { * // 是否開啟 sourceMap * sourceMap: true, * // 是否提取css * extract: true * } * @return {Object} 處理css的loaders配置對(duì)象 */ exports.cssLoaders = function (options) { options = options || {} var cssLoader = { loader: 'css-loader', options: { minimize: process.env.NODE_ENV === 'production', sourceMap: options.sourceMap } } /** * 生成 ExtractTextPlugin對(duì)象或loader字符串 * @method generateLoaders * @param {Array} loaders loader名稱數(shù)組 * @return {String|Object} ExtractTextPlugin對(duì)象或loader字符串 */ function generateLoaders (loader, loaderOptions) { var loaders = [cssLoader] if (loader) { loaders.push({ // 例如,sass?indentedSyntax // 在?號(hào)前加上“-loader” loader: loader + '-loader', options: Object.assign({}, loaderOptions, { sourceMap: options.sourceMap }) }) } // extract為true時(shí),提取css // 生產(chǎn)環(huán)境中,默認(rèn)為true if (options.extract) { return ExtractTextPlugin.extract({ use: loaders, fallback: 'vue-style-loader' }) } else { return ['vue-style-loader'].concat(loaders) } } // http://vuejs.github.io/vue-loader/en/configurations/extract-css.html return { css: generateLoaders(), postcss: generateLoaders(), less: generateLoaders('less'), sass: generateLoaders('sass', { indentedSyntax: true }), scss: generateLoaders('sass'), stylus: generateLoaders('stylus'), styl: generateLoaders('stylus') } } /** * 生成 style-loader的配置 * style-loader文檔:https://github.com/webpack/style-loader * @method styleLoaders * @param {Object} options 生成配置 * option = { * // 是否開啟 sourceMap * sourceMap: true, * // 是否提取css * extract: true * } * @return {Array} style-loader的配置 */ exports.styleLoaders = function (options) { var output = [] var loaders = exports.cssLoaders(options) for (var extension in loaders) { var loader = loaders[extension] output.push({ test: new RegExp('\\.' + extension + '$'), use: loader }) } return output }
生產(chǎn)環(huán)境
開發(fā)環(huán)境的入口文件是build/build.js 。
build.js
該文件,為構(gòu)建打包文件,會(huì)將源碼進(jìn)行構(gòu)建(編譯、壓縮等)后打包。
// 設(shè)置當(dāng)前環(huán)境為生產(chǎn)環(huán)境 process.env.NODE_ENV = 'production' // loading 插件 // https://github.com/sindresorhus/ora var ora = require('ora') // 可以在 node 中執(zhí)行`rm -rf`的工具 // https://github.com/isaacs/rimraf var rm = require('rimraf') // node自帶的文件路徑工具 var path = require('path') // 在終端輸出帶顏色的文字 // https://github.com/chalk/chalk var chalk = require('chalk') var webpack = require('webpack') // 配置文件 var config = require('../config') var webpackConfig = require('./webpack.prod.conf') // 在終端顯示loading效果,并輸出提示 var spinner = ora('building for production...') spinner.start() // 刪除這個(gè)文件夾 (遞歸刪除) rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { if (err) throw err // 構(gòu)建 webpack(webpackConfig, function (err, stats) { // 構(gòu)建成功 // 停止 loading動(dòng)畫 spinner.stop() if (err) throw err process.stdout.write(stats.toString({ colors: true, modules: false, children: false, chunks: false, chunkModules: false }) + '\n\n') // 打印提示 console.log(chalk.cyan(' Build complete.\n')) console.log(chalk.yellow( ' Tip: built files are meant to be served over an HTTP server.\n' + ' Opening index.html over file:// won\'t work.\n' )) }) })
webpack.prod.conf
該文件,為生產(chǎn)環(huán)境中webpack的配置入口。同時(shí),它也依賴于前面提到的webpack.base.conf.js、utils.js和config/index.js。
// node自帶的文件路徑工具 var path = require('path') // 工具函數(shù)集合 var utils = require('./utils') var webpack = require('webpack') // 配置文件 var config = require('../config') // webpack 配置合并插件 var merge = require('webpack-merge') // webpack 基本配置 var baseWebpackConfig = require('./webpack.base.conf') // webpack 復(fù)制文件和文件夾的插件 // https://github.com/kevlened/copy-webpack-plugin var CopyWebpackPlugin = require('copy-webpack-plugin') // 自動(dòng)生成 html 并且注入到 .html 文件中的插件 // https://github.com/ampedandwired/html-webpack-plugin var HtmlWebpackPlugin = require('html-webpack-plugin') // 提取css的插件 // https://github.com/webpack-contrib/extract-text-webpack-plugin var ExtractTextPlugin = require('extract-text-webpack-plugin') // webpack 優(yōu)化壓縮和優(yōu)化 css 的插件 // https://github.com/NMFR/optimize-css-assets-webpack-plugin var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin') // 如果當(dāng)前環(huán)境為測(cè)試環(huán)境,則使用測(cè)試環(huán)境 // 否則,使用生產(chǎn)環(huán)境 var env = process.env.NODE_ENV === 'testing' ? require('../config/test.env') : config.build.env var webpackConfig = merge(baseWebpackConfig, { module: { // styleLoaders rules: utils.styleLoaders({ sourceMap: config.build.productionSourceMap, extract: true }) }, // 是否開啟 sourceMap devtool: config.build.productionSourceMap ? '#source-map' : false, output: { // 編譯輸出的靜態(tài)資源根路徑 path: config.build.assetsRoot, // 編譯輸出的文件名 filename: utils.assetsPath('js/[name].[chunkhash].js'), // 沒有指定輸出名的文件輸出的文件名 chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') }, plugins: [ // definePlugin 接收字符串插入到代碼當(dāng)中, 所以你需要的話可以寫上 JS 的字符串 // 此處,插入適當(dāng)?shù)沫h(huán)境 // http://vuejs.github.io/vue-loader/en/workflow/production.html new webpack.DefinePlugin({ 'process.env': env }), // 壓縮 js new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false }, sourceMap: true }), // 提取 css new ExtractTextPlugin({ filename: utils.assetsPath('css/[name].[contenthash].css') }), // 壓縮提取出來的 css // 可以刪除來自不同組件的冗余代碼 // Compress extracted CSS. We are using this plugin so that possible // duplicated CSS from different components can be deduped. new OptimizeCSSPlugin(), // 將 index.html 作為入口,注入 html 代碼后生成 index.html文件 // https://github.com/ampedandwired/html-webpack-plugin new HtmlWebpackPlugin({ filename: process.env.NODE_ENV === 'testing' ? 'index.html' : config.build.index, template: 'index.html', inject: true, minify: { removeComments: true, collapseWhitespace: true, removeAttributeQuotes: true // 更多選項(xiàng) https://github.com/kangax/html-minifier#options-quick-reference }, // 必須通過 CommonsChunkPlugin一致地處理多個(gè) chunks chunksSortMode: 'dependency' }), // 分割公共 js 到獨(dú)立的文件 // https://webpack.js.org/guides/code-splitting-libraries/#commonschunkplugin new webpack.optimize.CommonsChunkPlugin({ name: 'vendor', minChunks: function (module, count) { // node_modules中的任何所需模塊都提取到vendor return ( module.resource && /\.js$/.test(module.resource) && module.resource.indexOf( path.join(__dirname, '../node_modules') ) === 0 ) } }), // 將webpack runtime 和模塊清單 提取到獨(dú)立的文件,以防止當(dāng) app包更新時(shí)導(dǎo)致公共 jsd hash也更新 // extract webpack runtime and module manifest to its own file in order to // prevent vendor hash from being updated whenever app bundle is updated new webpack.optimize.CommonsChunkPlugin({ name: 'manifest', chunks: ['vendor'] }), // 復(fù)制靜態(tài)資源 // https://github.com/kevlened/copy-webpack-plugin new CopyWebpackPlugin([ { from: path.resolve(__dirname, '../static'), to: config.build.assetsSubDirectory, ignore: ['.*'] } ]) ] }) // 開啟 gzip 的情況時(shí),給 webpack plugins添加 compression-webpack-plugin 插件 if (config.build.productionGzip) { // webpack 壓縮插件 // https://github.com/webpack-contrib/compression-webpack-plugin var CompressionWebpackPlugin = require('compression-webpack-plugin') // 向webpackconfig.plugins中加入下方的插件 webpackConfig.plugins.push( new CompressionWebpackPlugin({ asset: '[path].gz[query]', algorithm: 'gzip', test: new RegExp( '\\.(' + config.build.productionGzipExtensions.join('|') + ')$' ), threshold: 10240, minRatio: 0.8 }) ) } // 開啟包分析的情況時(shí), 給 webpack plugins添加 webpack-bundle-analyzer 插件 if (config.build.bundleAnalyzerReport) { // https://github.com/th0r/webpack-bundle-analyzer var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin webpackConfig.plugins.push(new BundleAnalyzerPlugin()) } module.exports = webpackConfig
其他
如果你覺得在segmentfault的代碼閱讀體驗(yàn)不好,你可以到我github上將代碼clone下來看。
總結(jié)
這次研究webpack配置的時(shí)候,我自己跟著源碼敲了一遍(很笨的方法),然后,在github和webpack官網(wǎng)上查使用到的插件的作用和用法。經(jīng)過這一次折騰,加深對(duì)webpack的認(rèn)識(shí)。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vuex報(bào)錯(cuò)之[vuex] unknown mutation type: han
這篇文章主要介紹了Vuex報(bào)錯(cuò)之[vuex] unknown mutation type: handlePower問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-07-07如何使用vue實(shí)現(xiàn)跨域訪問第三方http請(qǐng)求
這篇文章主要介紹了如何使用vue實(shí)現(xiàn)跨域訪問第三方http請(qǐng)求,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2024-03-03