Vue学习笔记——vue.config.js(路径别名)以及 .editorconfig(代码风格规定)
发布日期:2021-05-12 21:17:55 浏览次数:22 分类:原创文章

本文共 1793 字,大约阅读时间需要 5 分钟。

在主项目目录下分别创建一个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-8indent_style = spaceindent_size = 2end_of_line = lfinsert_final_newline = truetrim_trailing_whitespace = true
上一篇:在vue中使用better-scroll,完成平滑滚动效果
下一篇:Github的使用——项目托管(vue项目初始化、github仓库建立、提交项目)

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2025年04月06日 18时59分29秒