在主项目目录下分别创建一个vue.config.js(路径别名)以及 .editorconfig(代码风格规定)。
路径别名作用:
设置好了路径别名后,可在使用这些路径下的内容时,不用使用 **…/**来进行目录回退,
可直接使用别名,即使文件目录发生变化,只要规定的这些别名没有变化,则不需要改变。
路径别名设置举例:
module.exports = {
configureWebpack: {
resolve: {
alias: {
'assets': '@/assets',
'common': '@/common',
'components': '@/components',
'network': '@/network',
'views': '@/views',
}
}
}
}
使用方式如下:
①import等方式直接用别名
②在DOM中使用,则在前面需要加上 “~”
(分别在导入img时加上 ~,以及再导入组件时直接用components)
<template>
<tab-bar>
<tab-bar-item path="/home">
<img slot="item-icon" src="~assets/img/tabbar/home.svg" alt="">
<img slot="item-icon-active" src="~assets/img/tabbar/home_active.svg" alt="">
<div slot="item-text">首页</div>
</tab-bar-item>
<tab-bar-item path="/category">
<img slot="item-icon" src="~assets/img/tabbar/category.svg" alt="">
<img slot="item-icon-active" src="~assets/img/tabbar/category_active.svg" alt="">
<div slot="item-text">分类</div>
</tab-bar-item>
<tab-bar-item path="/cart">
<img slot="item-icon" src="~assets/img/tabbar/shopcart.svg" alt="">
<img slot="item-icon-active" src="~assets/img/tabbar/shopcart_active.svg" alt="">
<div slot="item-text">购物车</div>
</tab-bar-item>
<tab-bar-item path="/profile">
<img slot="item-icon" src="~assets/img/tabbar/profile.svg" alt="">
<img slot="item-icon-active" src="~assets/img/tabbar/profile_active.svg" alt="">
<div slot="item-text">我的</div>
</tab-bar-item>
</tab-bar>
</template>
<script>
import TabBar from 'components/common/tabbar/TabBar'
import TabBarItem from 'components/common/tabbar/TabBarItem'
代码风格规定举例:
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true