美文网首页
详解VUE中常用的几种import(模块、文件)引入方式

详解VUE中常用的几种import(模块、文件)引入方式

作者: 命题_1f6e | 来源:发表于2019-06-24 11:27 被阅读0次

1 引入第三方插件

1 import echarts from 'echarts'

2 引入工具类

第一种是引入单个方法

1 import {axiosfetch} from './util';

下面是写法,需要export导出

export function axiosfetch(options) {

}

第二种 导入成组的方法

import * as tools from './libs/tools

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

vue中怎么用呢?

1 Vue.prototype.$tools = tools

直接用 this.$tools.method调用就可以了

说到这 export 和 export default 又有什么区别呢?

下面看下区别

先是 export

import {axiosfetch} from './util';

//需要加花括号 可以一次导入多个也可以一次导入一个,但都要加括号

如果是两个方法

1 import {axiosfetch,post} from './util';

再是 export default

1 import axiosfetch from './util'; //不需要加花括号 只能一个一个导入
3.导入 css文件

?

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

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

<style>


@import './test.css';

</style>

4.导入组件


import name2 from './name2'

  components:{

     name1,

     name2,

  },

相关文章

网友评论

      本文标题:详解VUE中常用的几种import(模块、文件)引入方式

      本文链接:https://www.haomeiwen.com/subject/vyenqctx.html