Vue-04-import

1.引入第三方插件

import ElementUI from 'element-ui'

2.引入工具类

法一 引入单个方法

import { axiosfetch } from '../util/axios.js'
在axios.js里,需要expert导出
export function axiosfetch(options) {
.....
}

法二 导入成组的方法

import * as tools from './libs/tools'
其中tools.js中有多个export方法,把tools里所有export的方法导入
使用:
Vue.prototype.$tools = tools
直接用 this.$tools.method调用就可以了

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

Vue.prototype.\$tools = tools

this.$tools.xxx

3.引入css类

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

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

4.导入组件

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

5.导入js

import './libs/xxx.js'

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

然后引入

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

[].max();

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容