Vue項目開發(fā)常見問題和解決方案總結(jié)
Vue Cli 打包之后靜態(tài)資源路徑不對的解決方法
cli2版本:
將 config/index.js 里的 assetsPublicPath 的值改為 ’./’ 。
build: { ... assetsPublicPath: ’./’, ... }
cli3版本:
在根目錄下新建 vue.config.js 文件,然后加上以下內(nèi)容:(如果已經(jīng)有此文件就直接修改)
module.exports = { publicPath: ’’, // 相對于 HTML 頁面(目錄相同)}
Vue cli 3 報錯 error: Unexpected console statement (no-console) 解決辦法
在項目的根目錄下的 package.json 文件中的 eslintConfig:{} 中的 'rules': { 加入'no-console':'off' }, 其它類似報錯也是如此
// 示例:'eslintConfig': { 'root': true, 'env': { 'node': true }, 'extends': [ 'plugin:vue/essential', 'eslint:recommended' ], 'rules': { 'no-console':'off' },}
axios 取消請求 (如:用戶登錄失效,阻止其他請求)
const CancelToken = axios.CancelToken;const source = CancelToken.source();axios.interceptors.request.use( config => { config.cancelToken = source.token; // 全局添加cancelToken return config; }, err => { return Promise.reject(err); } );/** 設(shè)置響應(yīng)攔截 **/axios.interceptors.response.use( response => { // 登錄失效101 if ( response.data.code===101) { source.cancel(); // 取消其他正在進(jìn)行的請求 // some coding } return response; }, error => { if (axios.isCancel(error)) { // 取消請求的情況下,終端Promise調(diào)用鏈 return new Promise(() => {}); } else { return Promise.reject(error); } });
vue-photo-preview圖片預(yù)覽失效問題記錄
<img v-for='(item,index) of imgList' :key='index' :src='http://www.4tl426be.cn/bcjs/item.smallFileName' :large='item.fileName' preview='0' preview-text='癥狀圖片'>
imgList是異步獲取數(shù)據(jù)的時候在獲取數(shù)據(jù)后需要調(diào)用this.$previewRefresh();刷新重置一下,否則~~不生效
以上就是Vue項目開發(fā)常見問題和解決方案總結(jié)的詳細(xì)內(nèi)容,更多關(guān)于vue 常見問題和解決方案的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. 解決vue頁面刷新,數(shù)據(jù)丟失的問題2. python 讀txt文件,按‘,’分割每行數(shù)據(jù)操作3. python logging.info在終端沒輸出的解決4. vue路由分文件拆分管理詳解5. vue+vuex+axios從后臺獲取數(shù)據(jù)存入vuex,組件之間共享數(shù)據(jù)操作6. 詳解android adb常見用法7. SpringBoot使用Captcha生成驗證碼8. android studio實現(xiàn)簡單的計算器(無bug)9. android 控件同時監(jiān)聽單擊和雙擊實例10. Python 忽略文件名編碼的方法
