• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
ellaha
博客园    首页    新随笔    联系   管理    订阅  订阅
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();

 

posted on 2021-07-01 16:20  ellaha  阅读(749)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3