Vue import file import, and @ path. The difference Vue import file import, and @ path. The difference

Vue import file import, and @ path. The difference

 

Import ***:
HTML files by scriptlabel introduced js file.
And vue by import xxx from xxxintroducing path papers, can be introduced only js file.
"Xxx" refers to a name from the imported file, not the name of the guidance document, the equivalent of a variable name.
"Xxx path" refers to the relative path to the file.

E.g:

In the routing index.js introduced apple.vue and banana.vue

import banana from '@/components/banana'
import apple from '../components/apple'

Above example, a relative path is defined in two ways, and the file extension is omitted.

*** manner
as to define a parent-child directory relative path
. /refers to the current directory
. ./refers to a directory in the current directory

*** @ manner
as to define a relative path root
vue has the following configuration file in webpack.base.conf.js

// 连接路径并返回
function resolve(dir) { return path.join(__dirname, '..', dir) } module.exports = { resolve: { // 在导入语句没带文件后缀时,webpack会自动按照顺序添加后缀名查找 extensions: ['.js', '.vue', '.json'], // 配置别名 alias: { 'vue$': 'vue/dist/vue.esm.js', // 将项目根目录中,src的路径配置为别名@ '@': resolve('src'), } } }

Import ***:
HTML files by scriptlabel introduced js file.
And vue by import xxx from xxxintroducing path papers, can be introduced only js file.
"Xxx" refers to a name from the imported file, not the name of the guidance document, the equivalent of a variable name.
"Xxx path" refers to the relative path to the file.

E.g:

In the routing index.js introduced apple.vue and banana.vue

import banana from '@/components/banana'
import apple from '../components/apple'

Above example, a relative path is defined in two ways, and the file extension is omitted.

*** manner
as to define a parent-child directory relative path
. /refers to the current directory
. ./refers to a directory in the current directory

*** @ manner
as to define a relative path root
vue has the following configuration file in webpack.base.conf.js

// 连接路径并返回
function resolve(dir) { return path.join(__dirname, '..', dir) } module.exports = { resolve: { // 在导入语句没带文件后缀时,webpack会自动按照顺序添加后缀名查找 extensions: ['.js', '.vue', '.json'], // 配置别名 alias: { 'vue$': 'vue/dist/vue.esm.js', // 将项目根目录中,src的路径配置为别名@ '@': resolve('src'), } } }

Guess you like

Origin www.cnblogs.com/frank0812/p/12159587.html