Home > Web Front-end > JS Tutorial > An introduction to several import methods commonly used in VUE (modules, files)

An introduction to several import methods commonly used in VUE (modules, files)

不言
Release: 2018-07-03 14:18:05
Original
4699 people have browsed it

This article mainly introduces in detail several import methods commonly used in VUE (modules, files). The content is quite good. I will share it with you now and give it as a reference.

1 Introducing third-party plug-ins

import echarts from 'echarts'
Copy after login

2 Introducing tool classes

The first is to introduce a single method

import {axiosfetch} from './util';
Copy after login

The following is the writing method, which needs to be exported

export function axiosfetch(options) {

}
Copy after login

The second method of importing groups

import * as tools from './libs/tools'
Copy after login

There are multiple export methods in tools.js, and all exports in tools How to use the method imported into

vue?

Vue.prototype.$tools = tools
Copy after login

Just call this.$tools.method directly

Speaking of export and export default What's the difference?

Let’s take a look at the difference

First, export

import {axiosfetch} from './util'; 
 //需要加花括号 可以一次导入多个也可以一次导入一个,但都要加括号
Copy after login

If there are two methods

import {axiosfetch,post} from './util';
Copy after login

Then export default

import axiosfetch from './util'; //不需要加花括号 只能一个一个导入
Copy after login

3 .Import the css file

import 'iview/dist/styles/iview.css';
Copy after login

If it is in the .vue file, then put a style outside it

<style>
 @import &#39;./test.css&#39;; 

</style>
Copy after login

4. Import components

 import name1 from &#39;./name1&#39;
import name2 from &#39;./name2&#39;
  components:{
     name1,
     name2,
  },
Copy after login

The above is the entire content of this article, I hope it will be useful for everyone’s learning For help, please pay attention to the PHP Chinese website for more related content!

Related recommendations:

JQuery prevents event bubbling instance analysis

About vue’s ideas for solving cross-domain routing conflicts

Introduction to Vue dynamically setting routing parameters

The above is the detailed content of An introduction to several import methods commonly used in VUE (modules, files). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template