安装@vue/cli
yarn global add @vue/cli
创建项目
vue create vue-evernote
启动项目
cd vue-evernote
yarn serve
vscode创建vue模板
ctrl+shift+p 搜索 snippets
搜索vue, 选择第一个打开vue.json
添加下列代码
"Print to console": {
"prefix": "vue",
"body": [
"<template>",
" <div class=\"wrapper\">$0</div>",
"</template>",
"",
"<script>",
"export default {",
" components: {},",
" props: {},",
" data() {",
" return {",
" };",
" },",
" watch: {},",
" computed: {},",
" methods: {},",
" created() {},",
" mounted() {}",
"};",
"</script>",
"",
"<style lang=\"scss\" scoped>",
".wrapper{}",
"</style>"
],
"description": "A vue file template"
}
当新建一个.vue文件时,输入vue后敲Tab键则自动生成vue模板
使用vue-router
参看官方文档即可:https://router.vuejs.org/zh/
import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '@/components/Login'
import NotebookList from '@/components/NotebookList'
import Note from '@/components/NoteDetail'
import Trash from '@/components/TrashDetail'
import NotFound from '@/components/NotFound'
Vue.use(VueRouter)
const routes = [
{
path: '/',
redirect: '/login'
},
{
path: '/login',
component: Login
},
{
path: '/notebooks',
component: NotebookList
},
{
path: '/note/:noteId',
component: Note
},
{
path: '/trash/:noteId',
component: Trash
},
{
path: '*',
component: NotFound
}
]
const router = new VueRouter({
routes
})
export default router
让vscode自动import
安装auto import插件