vue开发过程中遇到的一些小问题、小技巧等,会不断更新~
记录不详细处,欢迎留言?
1.设置路径别名,以后再引入static/util/Geometry.js 文件时可以这样写:
1 import geometry from '@/util/Geometry'
2.使用前端组件引入自定义标签时eslint会报错,可以加入一下配置忽略检查
1 'vue/no-parsing-error': [2, { "x-invalid-end-tag": false }]
3.打包后部署出现空白页,修改assetsPublicPath
4.iview图标build后不显示的问题
修改webpack.prod.conf.js文件 extract: false
1 const webpackConfig = merge(baseWebpackConfig, { 2 module: { 3 rules: utils.styleLoaders({ 4 sourceMap: config.build.productionSourceMap, 5 extract: false, 6 usePostCSS: true 7 }) 8 },
或者修改build/utils文件,添加
publicPath: '../../'配置
1 // Extract CSS when that option is specified 2 // (which is the case during production build) 3 if (options.extract) { 4 return ExtractTextPlugin.extract({ 5 use: loaders, 6 publicPath: '../../', // 解决打包后iView的icon不显示的问题 7 fallback: 'vue-style-loader' 8 }) 9 } else { 10 return ['vue-style-loader'].concat(loaders) 11 }
5.开启Gzip
6.修改数组vue不能侦测到变化
例如,需要修改数组最后一项的值,可以这样
1 // 不可以直接使用this.layers[index][2] = '',这样VUE侦听不到数组的变化,不会触发view变化 2 this.layers[index].pop() 3 this.layers[index].push('')
不过,vue对数组进行了增强,可以更优雅:
1 Vue.$set(array, index, value) 2 this.$set(array, index, value) // 实例中使用