vue 各種 import 引入

1 引入第三方插件

import echarts from 'echarts'

2 引入工具類

第一種是引入單個(gè)方法

import {axiosfetch} from './util';

下面是寫法,需要export導(dǎo)出
export function axiosfetch(options) {

} 
第二種  導(dǎo)入成組的方法

import * as tools from './libs/tools'

其中tools.js中有多個(gè)export方法,把tools里所有export的方法導(dǎo)入

vue中怎么用呢?
Vue.prototype.$tools = tools
直接用 this.$tools.method調(diào)用就可以了

說到這 export 和 export default 又有什么區(qū)別呢?
下面看下區(qū)別

 先是 export 
import {axiosfetch} from './util';  //需要加花括號(hào)  可以一次導(dǎo)入多個(gè)也可以一次導(dǎo)入一個(gè),但都要加括號(hào)
如果是兩個(gè)方法
import {axiosfetch,post} from './util'; 
再是 export default 
import axiosfetch from './util';  //不需要加花括號(hào)  只能一個(gè)一個(gè)導(dǎo)入

3.導(dǎo)入 css文件

import 'iview/dist/styles/iview.css';

如果是在.vue文件中那么在外面套個(gè)style

<style>
  @import './test.css'; 

</style>

4.導(dǎo)入組件

 import name1 from './name1'
import name2 from './name2'
    components:{
         name1,
         name2,
    },

5.導(dǎo)入js

比如你想給Arrary封一個(gè)屬性,首先需要新建一個(gè)prototype.js的文件
文件里
Array.prototype.max = function(){ 
    return Math.max.apply({},this); 
}

然后引入

import './libs/prototype'
在main.js中引用那么在所有的組件都可以用

[].max();
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容