vue 各種 import 引入


1 引入第三方插件

import echarts from 'echarts'

2 引入工具類

第一種是引入單個方法

import {axiosfetch} from './util';

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

} 
第二種  導入成組的方法

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

其中tools.js中有多個export方法,把tools里所有export的方法導入

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

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

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

3.導入 css文件

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

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

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

</style>

4.導入組件

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

5.導入js

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

然后引入

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

[].max();

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM