前端(vue)入門到精通課程:進(jìn)入學(xué)習(xí)
Apipost = Postman + Swagger + Mock + Jmeter 超好用的API調(diào)試工具:點(diǎn)擊使用
vscode
自身是支持vue文件組件跳轉(zhuǎn)到定義的,但是支持的力度是非常弱的。我們?cè)?code>vue-cli的配置的下,可以寫很多靈活的用法,這樣可以提升我們的生產(chǎn)效率。但是正是這些靈活的寫法,導(dǎo)致了vscode自身提供的功能無(wú)法支持跳轉(zhuǎn)到文件定義。為了兼容這些靈活的寫法,提高工作效率,所以寫了一個(gè)vscode支持vue文件跳轉(zhuǎn)到定義的插件。【推薦學(xué)習(xí):《vscode教程》】
插件
vscode支持vue文件跳轉(zhuǎn)到定義的插件(vue jumper
)已正式發(fā)布到vscode插件市場(chǎng),可以到vscode插件市場(chǎng)直接下載體驗(yàn)。
功能
該插件支持vue-cli提供給我們很多組件引用寫法的跳轉(zhuǎn)支持。
1、省略寫法跳轉(zhuǎn)支持
我們?cè)谝媒M件的時(shí)候,如果組件的名稱是index.vue
或者index.js
時(shí),我們引入時(shí)可以省略index.vue或者index.js。如果我們使用了省略寫法,vscode自身是無(wú)法支持跳轉(zhuǎn)的,所以該插件需要支持省略寫法跳轉(zhuǎn)。
import MycoMponent from '../components/MyComponent' // '../components/MyComponent/index.vue'
2、alis別名路徑跳轉(zhuǎn)支持
在vue-cli(webpack)的配置下,我們可以配置alis別名,這樣我們可以提升生產(chǎn)效率,但是vscode本身是不支持的,所以該插件需要支持alis別名路徑跳轉(zhuǎn)。
import MycoMponent from '@/components/MyComponent'
3、components注冊(cè)別名跳轉(zhuǎn)支持
vscode本身是支持components注冊(cè)別名跳轉(zhuǎn)的(如果引入時(shí)有省略寫法和alis別名路徑也是不支持的),所以該插件也需要支持components注冊(cè)別名跳轉(zhuǎn)。
<script> import MycoMponent from '@/components/MyComponent' export default { components: { MycoMponentReName: MycoMponent } } </script>
4、mixins中引入的組件跳轉(zhuǎn)支持
在實(shí)際開發(fā)中,我們可以有很多復(fù)用的功能抽離到了mixins
中,其中包含了組件的引入和注冊(cè),這個(gè)vscode本身是不支持跳轉(zhuǎn)的,所以該插件支持mixins引入的情況。
<template> <MyComponent /> </template> <script> import myMixins from '@/mixins/myMixins' export default { mixins: [myMixins] } </script>
// myMixins.js import MycoMponent from '@/components/MyComponent' export default { components: { MycoMponent } }
5、全局組件引入跳轉(zhuǎn)支持
在全局中注冊(cè)的組件,vscode本身是不支持這種情況的跳轉(zhuǎn)的。由于全局組件引入的情況比較復(fù)雜,該插件使用了模糊查找的方式來(lái)查找組件定義的地方,做到了全局組件引入的跳轉(zhuǎn)支持。
<template> <MyComponent /> </template> <script>
// main.js import vue from 'vue' import MycoMponent from './components/MyComponent' vue.use(MycoMponent)