對於第三方框架或者一些封裝的內置組件,若是想綁定事件,須要再v-on
上添加修飾符.native
javascript
<my-component v-on:click.native="doTheThing"></my-component>
由於整個IE系列都不支持promise的緣故,因此沒法使用promise,這裏須要用到一個墊片css
npm install es6-promise // 在main.js中引入 require('es6-promise').polyfill()
常常遇到的報錯No 'Access-Control-Allow-Origin' header is present on the requested resource.
html
1:CORS
,先後端都對應配置,IE10+vue
2:nginx
反向代理java
線下開發,若是使用了vue-cli
,裏面的webpack引入了proxyTable
能夠作接口反向代理webpack
// 在config目錄下的index.js proxyTable: { "/bp-api": { target: "http://pengzhixin.com", changeOrigin: true, // pathRewrite: { // "^/api": "/" // } } } // target: api代理的實際路徑 // changeOrigin: 改變源頭 // pathRewrite: 路徑重定向
除此以外,jsonp
請求能夠,但侷限性不少。nginx
在開發環境中,背景圖片都顯示正常,可是一打包上傳到生產環境就發現有一些背景圖片沒法正常顯示,觀察DOM發現圖片路徑指向錯誤了。es6
// build/webpack.bas.conf.js module:{ rules:[ { { test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, loader: 'url-loader', options: { limit: 10000, name: utils.assetsPath('img/[name].[hash:7].[ext]') } } } ] }
因爲vue-cli的默認配置,小於10k的資源都會打包成base64,因此沒有這個問題。web
咱們發現發生問題的都是大於10k的靜態圖片資源。vue-cli
若是你使用了路由懶加載,也不會出現這個問題,由於路由懶加載最終的css是以style標籤插入到index.html裏面的。
咱們還可使用import或require引入這些過大的圖片而後寫成行內樣式。但最簡單的方法是如下這種:
// 在build/utils.js文件中的generateLoaders函數中加上publicPath配置項 if (options.extract) { return ExtractTextPlugin.extract({ use: loaders, publicPath: '../../', fallback: 'vue-style-loader' }) } else { return ['vue-style-loader'].concat(loaders) }