您好,欢迎访问一九零五行业门户网

vue高级视频教程(vue 高阶)

本文主要介绍vue高级视频教程(vue高级),下面一起看看vue高级视频教程(vue高级)相关资讯。
目录21,项目建设规范1,创建项目2,代码规范a,。editorconfig(编辑器编辑样式)b、appellizer(代码格式化样式)c、eslint(代码样式检测工具)d、git husky(提交前的代码格式化样式)e、commitizen(提交信息格式化样式)f、commitlint 3。项目结构a,vue.config.jsb,vue-routerc,vuexd,element-pluse,axiosf,环境变量g,tsconfig.jsonh,shims-vu:-手动选择功能?检查您的project:所需的功能-选择vue版本,巴别塔,ts,路由器,vuex,css预处理器,linter?选择一个您希望用- 3.x启动项目的vue.js版本?使用类样式的组件语法?-没有吗?在typescript旁边使用babel(现代模式、自动检测的polyfills、transpiling jsx所需的)?-什么事?对路由器使用历史模式?(需要为生产中的索引回退设置正确的服务器)-否?挑选一个css预处理器(postcss、autoprefixer和css模块受d:-萨斯/scss(带dart-萨斯)支持)?选择阿林config:-更漂亮?选择额外的皮棉f:-皮棉保存?你更喜欢把babel,eslint等的配置放在哪里??-在专用配置文件中?将此存储为未来项目的预置?-没有吗?选择安装dependenci:-npm2时使用的软件包管理器,代码规范a,。editor config # root = true[*]#表示charset = utf-8 #适用于所有文件,文件字符集为utf-8 indent _ style = space # indent _ size = 2 #缩进大小end_of_line = lf #控制换行符类型(lf | cr | crlf)trim _ trailing _ white space = true #删除行首的任何空白字符insert_final_newline = true #总是在文件末尾插入一个新行[*。md] #表示只有md文件服从以下规则:max _ line _ length = off trim _ trailing _ white spac:假,;tabwidth;: 2,;printwidth;: 80,;singl:真,;trailingcomma;:和;无 、;s: false } * use tabs:使用制表符缩进或空格缩进,并选择false * tabwidth:空格的情况下有多少个制表符?空格,选择两个* printwidth:一个行字符的长度推荐时,推荐80,也有人偏爱100或120* singlequote:使用单引号或双引号,选择true,使用单引号* trailingcomma:是否添加多行输入的尾部逗号,设置为` none`* semi:是否在句尾添加符号,默认值为true,选择false表示不添加。pretierignore/dist/*。local.output.js/node _模块/* * */*。svg * */*。sh/public/* package . json { ;scripts;: { ;pr: 写得更漂亮。 }}c、eslint(代码风格检测工具)安装npm i-d eslint-plugin-pretier eslint-config-pretier . eslintrc . jsmodul: tru: { nod: tru:[ ;plugin: vue/vue 3-essential ;, eslint:推荐 , @ vue/typescript/推荐 , @ vue/beauty ;, @ vue/appeller/@ typescript-eslint ;,//解决eslint和pretier 插件:普雷蒂尔/推荐 ]、pars: {ecmav: 2020 }、rul: { ;no-consol: proc: ;关闭 ,;no-d: proc: ;关闭 , @ typescript-: ;关闭 , @ typescript-eslint/no-explicit-any ;: ;关闭 ,@ typescript-eslint/explicit-module-boundary-types ;: ;关闭 } d、git husky(提交前代码格式化样式)命令# # # # # # # # # # # 1,用于拦截git命令#-多一个包的依赖。json ({;devdependenci: {;husky;:公司 } })#-再来一张。哈斯基目录下的项目#-包。json有一个以上的脚本({;scripts;: {;pr: 哈斯基安装和安装;} })# # # # # # # # # # install.husky/pre-commit#!. npx哈士奇-init npm/usr/bin/env sh。 $(dirname- 0美元 )/_/husky . sh npm runlint,commitizen(提交信息的格式样式)安装npm i -d commitizen命令# # # # # # # # # 1。-package.json多了一个依赖项({;devdependenci: {;cz-conventional-chang: }}) #-package.json多了一个配置#({;config;: {;commitiz: {;path;: 。/node _ modules/cz-conventi on-changelog } } })# # # # # # # # # # # # # # npx commit izen initcz-convention-changelog-save-dev-save-exact package . json(代码的gi不使用这个脚本提交){;scripts;: {;commit;: cz }}选项?选择您要更改的类型。;re committing cho3-@ . com-投稿类型?这个改动的范围(如组件或文件名):-提交范围?写一个简短、紧急的变更描述(最多87个字符):-简短描述信息提交?提供chang:的详细描述-详细描述信息提交?有什么突破性的变化吗?-没有吗?此更改是否会影响任何未解决的问题?no submission类型用于添加功能feat、修复bug、修改文档、修改样式代码格式(空白、格式、缺少分号等)refactor代码refactor)perf改善性能(改善性能的代码更改)test测试(添加缺少的测试时)。build改变了项目的构造或外部依赖关系(如scop: web pack、gulp、npm等。)ci更改持续集成软件的配置文件,并在包中编写命令脚本,例如scop:的travis。圈等杂务改变构建流程或辅助工具(如改变测试环境)revert code back f、commitlint(提交信息风格检测工具)安装npm i -d @commitlint/config-committal @ committal/cli committal . config . js modul:[ ;@ committal/config-conventi on ;]}命令# # # # # # # # # # # # # 1。项目中的一个变化:多了一个commit-msg文件# # # # # # # # # # npx哈斯基添加。哈士奇/提交-消息和npx-不安装提交林特-编辑$ 1 3,项目结构a,vue . config . js const path = r:配置(推荐)outputdir: ;距离和距离。;通过vue cli提供的选项。publicpath: ;/ ;、// 2、模式2 :通过configurewebpack(与webpack配置选项一致)// 2.1、对象:configurewebpack: {r: {alias: { components: ;@/组件 }}带有合并的webpack配置。// 2.2.功能:修改web pack/* configurewebpack:(config)= { config . r: path . resolve(_ _ dirname, src ),compon: ;@/组件 } }, *//3.三:通过chainwebpack修改webpack的配置(与webpack的配置选项一致)// 3.1。函数:chainwebpack:(配置)= { config . resolve . alias . set( ;@ ,path.resolve (_ _ dirname, src )).et( ;组件及配件。;, @/组件 )} */} b、vue-router安装npm i-vue-router @ nextsrc/router/index . t import { create router,createwebhashhistory } from vue-路由器 从 amp导入类型{ routerecordraw };;vu: arrayrouterecordraw =[{ path: ;/ ;、redirect: ;/hom: ;/home ;,compon:=进口( ../vi: ;/关于 ,compon:=进口( ../views/about . vue ;)}]const router = cr: createwebhashhistory,routes})导出默认路由器rc/main . t import { create app } from ;vue 从导入应用程序 。/app . vue ;从导入路由器 。/路由器 const app = create app(app)app . use(router)app . mount( ;# app )src/app.vuetemplate div路由器-link to = /home 家庭/路由器-链接路由器-链接到= /关于 关于/router-link/div router-view//template c,vuex安装npm i-svuex @ nextsrc/store/index . tsimport { cr: iuserstate }导出默认cr: {用户}})导出函数use store{ return usevuexstoreirootstate} src/stor:字符串us: { id:字符串nicknam:字符串} } const us: modulei userstate,irootstate = { namespac: tru: ; ,us: { id: ; 、nicknam: ; } } },mutations: { },actions: { } }导出默认用户src/main . t从 vue 从导入应用程序 。/app . vue ;从导入商店 。/store ;const app = create app(app)app . use(store)app . mount( ;# app )src/app . vue template div/div/template script lang = ts 从 amp导入{ definecomponent };;vue 从 amp导入{ usestore };;@/store ;导出默认定义组件({ setup{ const store = use storeconsole . log(store . state . user . token)return { } })/script style lang = scss scoped/style、element-plus安装npm i-s element-plus src/main . tsimport { create app } from ;vue 从导入应用程序 。/app . vue ;从导入element plus ;元素加 进口与贸易。;element-plus/dist/index .;const app = create app(app)app . use(element plus)app . mount( ;# app )src/ app。vue模板el按钮类型= 小学和初中黄婷婷/el-button/templatee,axios安装npm i -s axios知识点* promiseany指定泛型,那么resolve的res(res)和。然后(res={})是任意类型*默认值axios配置优先级:请求的配置参数实例的defaults属性* axios实例的多个拦截器将被合并。执行顺序是src/utils/request . tsimport axios from ;axios和。;从 amp导入类型{axiosrequestconfig};;axios和。;从 amp导入cookies;js-cookie ;const service = axios . cr: proc: 5000 })服务。interceptors . request . use((config)= {//1,add token const token = cookies。获取( token )if (tokenconfig。头)添加到请求头。{ config . headers . authorization = ` bearer $ { token } `} return config },(错误)= {返回承诺。拒绝(错误)})服务。截击机。回应。使用((response) = {//2),状态码开关(response.data.cod:控制台. log( ;误差 )break default : } return response }、(error) = {// 3、状态码开关(error.response.status)用于处理http { cas: console . log( ;未经认证或令牌过期。;).break cas:控制台。;拒绝未经授权的访问。;)br:}退货承诺。reject (error)})接口iresponsebodyt = any { cod:号data: t m:字符串}导出默认函数t = any(config: axiosrequestconfig): promiseiresponsebodyt { return service(config))。then((res)= { return res . data })} src/api/us:任何){返回请求({ url: ;/用户/登录 、m: ;邮政和邮政。;,data })} src/app . vue template div/div/template script lang = ts 从导入{ definecomponent } vue 从 @/api/用户 导出默认的define component({ setup{ log in({ })。然后((res)= { console . log(res)})return { } })/script style lang = scss /stylef,环境变量* mode:-script命令:vue-cli-service serve(默认模式开发)参考文件:。env . developnode env:process . env . node _ env = 发展与创新-脚本命令:vue-cli-servicebuilding。d(默认模式生产)参考文件:。env . production ode _ env:process . env . node _ env = 生产与销售-script命令:vue-cli-服务构建模式转移(手动指定)参考文件:。env.st agingnode _ env: process。环境。node _ env = 舞台表演和表演* node _ env变量不需要手动赋值*其他变量在自动注入代码之前应该以vue_app_开头*。环境优先级低于环境开发或环境生产等。ts config . json {;compil: {//目标代码:巴别编译(esnext),tsc编译(: : umd esnext ,//ts严格模式;strict;:真,//jsx待遇:不保存;jsx;: 保存 ,//导入函数辅助;importh:为真。//模块分析查找文件(节点) 模块分辨率和尺寸后缀顺序回显3-@ q。q.com 节点 ,//跳过第三方库的类型检测,;skiplibcheck;: tru: true混合在模块化方案中。 allowsyntheticd:为真,//是否生成映射文件;sourc:为真,//文件解析路径为;bas: 。 ,//分辨率类型;typ:[ 网络包-环境与环境],//路径别名(对应webpack配置);paths;: {;@/*;:[ src/* ]},//基本类型库;lib;:[ esnext , dom , 多姆。iterable , scripthost ]}、;includ:[ src/* */*。ts , src/* */*。tsx , src/**/*。vue , 测试/**/*。ts , 测试/**/*。tsx ],;exclud:[ 节点_模块 ]} h,shims-vue.d.ts/* eslint-disable */* * 1。声明。vue文件:导出的组件对象的类型。vue文件被定义为组件{},{},any * 2,.vue文件定义组件函数:*-源代码:函数定义组件(选项){返回选项} *-函数:选项可以限制在type */declare module ;* .vue {从 amp导入类型{定义组件};;vue const compon:定义组件{},{},anyexport默认组件} xxii。项目实战细节1。获取组件实例的类型父级。组件模板div son-component ref = soncomponentref /son-componentel-button @ click = 点击处理程序 减去1个按钮/el-button/div/template script lang = ts 从 amp导入{ definecomponent,ref };;vue 从导入son component ;。/son-component . vue ;导出默认的define component({ compon: { son component },setup{ constsoncomponentref = reftype soncomponenttype = soncomponent的instance typetype constclichandler == {/* * 1、函数签名以new关键字为前缀:*-var bankaccount: new= bank account;*那么bankaccount函数只能以new bankaccount的调用* 2和instancetype来获取构造函数的实例类型:son组件的instance type*获取子组件实例的类型*/const soncomponentinstanc: soncomponenttype = soncomponentref。值//3。组件实例中的属性不是ref对象,而是代理对象。所以你不 不需要。值soncomponentstance。人。age-} return {soncomponentref,clickhandler} }})/script子组件template div { { person } }/div el-button @ click = 点击处理程序 外加1个按钮/el-button/templates criptlang = ts 从 vue 导出默认d。efinecomponent({ setup{ const person = ref({ name : ;黄婷婷 ,ag: 18 })const click handler == { person。value.age} return {person,clickhandler}})/script标记:
代码文件
了解更多vue高级视频教程(vue高级)相关内容请关注本站点。
其它类似信息

推荐信息