安装@vue/cli

  1. yarn global add @vue/cli

创建项目

  1. vue create vue-evernote

启动项目

  1. cd vue-evernote
  2. yarn serve

vscode创建vue模板

ctrl+shift+p 搜索 snippets
image.png
搜索vue, 选择第一个打开vue.json
添加下列代码

  1. "Print to console": {
  2. "prefix": "vue",
  3. "body": [
  4. "<template>",
  5. " <div class=\"wrapper\">$0</div>",
  6. "</template>",
  7. "",
  8. "<script>",
  9. "export default {",
  10. " components: {},",
  11. " props: {},",
  12. " data() {",
  13. " return {",
  14. " };",
  15. " },",
  16. " watch: {},",
  17. " computed: {},",
  18. " methods: {},",
  19. " created() {},",
  20. " mounted() {}",
  21. "};",
  22. "</script>",
  23. "",
  24. "<style lang=\"scss\" scoped>",
  25. ".wrapper{}",
  26. "</style>"
  27. ],
  28. "description": "A vue file template"
  29. }

当新建一个.vue文件时,输入vue后敲Tab键则自动生成vue模板

使用vue-router

参看官方文档即可:https://router.vuejs.org/zh/

  1. import Vue from 'vue'
  2. import VueRouter from 'vue-router'
  3. import Login from '@/components/Login'
  4. import NotebookList from '@/components/NotebookList'
  5. import Note from '@/components/NoteDetail'
  6. import Trash from '@/components/TrashDetail'
  7. import NotFound from '@/components/NotFound'
  8. Vue.use(VueRouter)
  9. const routes = [
  10. {
  11. path: '/',
  12. redirect: '/login'
  13. },
  14. {
  15. path: '/login',
  16. component: Login
  17. },
  18. {
  19. path: '/notebooks',
  20. component: NotebookList
  21. },
  22. {
  23. path: '/note/:noteId',
  24. component: Note
  25. },
  26. {
  27. path: '/trash/:noteId',
  28. component: Trash
  29. },
  30. {
  31. path: '*',
  32. component: NotFound
  33. }
  34. ]
  35. const router = new VueRouter({
  36. routes
  37. })
  38. export default router

注意redirect重定向和404页面的写法

让vscode自动import

安装auto import插件
image.png