diff --git "a/\351\231\206\344\270\207\347\201\257/IMG/06-08/1.png" "b/\351\231\206\344\270\207\347\201\257/IMG/06-08/1.png" new file mode 100644 index 0000000000000000000000000000000000000000..308618c25bcacb160266d380cc7ec403ea253e2e Binary files /dev/null and "b/\351\231\206\344\270\207\347\201\257/IMG/06-08/1.png" differ diff --git "a/\351\231\206\344\270\207\347\201\257/IMG/06-12/1.png" "b/\351\231\206\344\270\207\347\201\257/IMG/06-12/1.png" new file mode 100644 index 0000000000000000000000000000000000000000..15d720296774e74daa091bd4a49b535dbeaf307b Binary files /dev/null and "b/\351\231\206\344\270\207\347\201\257/IMG/06-12/1.png" differ diff --git "a/\351\231\206\344\270\207\347\201\257/IMG/06-15/1.png" "b/\351\231\206\344\270\207\347\201\257/IMG/06-15/1.png" new file mode 100644 index 0000000000000000000000000000000000000000..7e6662fa92a108e799d941fefd71fa73e37e8190 Binary files /dev/null and "b/\351\231\206\344\270\207\347\201\257/IMG/06-15/1.png" differ diff --git "a/\351\231\206\344\270\207\347\201\257/IMG/06-15/\344\273\243\347\240\201.txt" "b/\351\231\206\344\270\207\347\201\257/IMG/06-15/\344\273\243\347\240\201.txt" new file mode 100644 index 0000000000000000000000000000000000000000..4f10e90368b47f6eed1a22484a8e63467221847f --- /dev/null +++ "b/\351\231\206\344\270\207\347\201\257/IMG/06-15/\344\273\243\347\240\201.txt" @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + +import Vue from "vue"; +import VueRouter from "vue-router"; + +// 引入组件 +import home from "./home.vue"; +import about from "./about.vue"; + +// 要告诉 vue 使用 vueRouter +Vue.use(VueRouter); + +const routes = [ + { + path:"/home", + component: home + }, + { + path: "/about", + component: about + } +] + +var router = new VueRouter({ + routes +}) +export default router; + + + + + +import Vue from 'vue' +import App from './App.vue' + +// 引入路由 +import router from "./router.js" // import router 的router 一定要小写, 不要写成Router, 否则报 can't match的报错 +new Vue({ + el: '#app', + router, // 注入到根实例中 + render: h => h(App) +}) \ No newline at end of file diff --git "a/\351\231\206\344\270\207\347\201\257/note-2021-06-08.md" "b/\351\231\206\344\270\207\347\201\257/note-2021-06-08.md" new file mode 100644 index 0000000000000000000000000000000000000000..065490c4763b7f261ac61cfb0c6f4a6a3f867372 --- /dev/null +++ "b/\351\231\206\344\270\207\347\201\257/note-2021-06-08.md" @@ -0,0 +1,91 @@ +# 组件基础 +## 基本实例 ++ 组件是可复用的Vue实例 且带有一个名字 Vue.component('组件名',{属性}) ++ 因为组件是一个可复用的Vue实例 所以他跟new Vue可以接收一样的选项 比如data、computed、watch、methods 以及生命周期钩子等 但el是一个例外 +## +
+ +
+ Vue.component('button-counter', { + data: function () { + return { + count: 0 + } + }, + template: '' + }) + new Vue({ + el: "#components-demo" + }) ++ 通过new Vue创建的Vue根实例,把这个组件作为自定义元素来使用 +## 组件的复用 ++ 可以将组件进行任意次数的复用 ++ 你每用一次组件,就会有一个它的新实例被创建 ++ 每个组件都会各自独立维护它的 count +### data 必须是一个函数 ++ 定义组件的时候发现data并不是像data:{count:0} 这样提供一个对象 ++ 而必须是一个函数因此每个实例可以维护一份被返回对象的独立的拷贝 +#### + data: function () { + return { + count: 0 + } + } +### 通过 Prop 向子组件传递数据 ++ Prop 是你可以在组件上注册的一些自定义特性。当一个值传递给一个 prop 特性的时候,它就变成了那个组件实例的一个属性 ++ 一个组件默认可以拥有任意数量的 prop,任何值都可以传递给任何 prop +### + Vue.component('blog-post', { + props: ['title'], + template: '

{{ title }}

' + }) ++ 在上面的模板中,你会发现我们能够在组件实例中访问这个值,就像访问 data 中的值一样。 +### +
+ + + +
+ Vue.component('blog-post', { + props: ['aa','bb'], + template: '

{{ aa }} {{bb}}

' + }) + new Vue({ el: '#app' }) ++ 看上面要在prop里写入bb 才能将bb作为那个组件的一个属性 +### 单个根元素 ++ 如果在组件模板中这样写 +### +

{{ post.title }}

+

{{post.content}}

+### 那会报错 +![picture](./IMG/06-08/1.png) ++ [Vue warn]:错误编译模板:yue.js: 634组件模板应该只包含一个根元素。如果在多个元素上使用v-if,则使用v-else-if将它们链起来。 ++ 因为每个组件必须只有一个根元素 ++ 可以将模板的内容包裹在一个父元素内,来修复这个问题,例如:用一个div把这两个包裹起来 ++ 组件变得越来越复杂的时候为每个相关的信息定义一个 prop 会变得很麻烦 需要重构一下 +## + + Vue.component('blog-post', { + props: ['post'], + template: ` +
+

{{ post.id }}

+

{{ post.title }}

+

{{ post.content}}

+
+ ` + }) + new Vue({ + el: '#app', + data: { + posts: [ + { id: 1, title: 'My journey with Vue', content: '小小陆' }, + { id: 2, title: 'Blogging with Vue' }, + { id: 3, title: 'Why Vue is so fun' } + ] + } + }) ++ 为 post 对象添加一个新的 property,它都会自动地在` ` 内可用 \ No newline at end of file diff --git "a/\351\231\206\344\270\207\347\201\257/note-2021-06-09.md" "b/\351\231\206\344\270\207\347\201\257/note-2021-06-09.md" new file mode 100644 index 0000000000000000000000000000000000000000..28107366601984f6c90306c75cef7523d8307fca --- /dev/null +++ "b/\351\231\206\344\270\207\347\201\257/note-2021-06-09.md" @@ -0,0 +1 @@ +# 插槽 \ No newline at end of file diff --git "a/\351\231\206\344\270\207\347\201\257/note-2021-06-11.md" "b/\351\231\206\344\270\207\347\201\257/note-2021-06-11.md" new file mode 100644 index 0000000000000000000000000000000000000000..19680a262f2133b811f14aebea95e55ce96f97a0 --- /dev/null +++ "b/\351\231\206\344\270\207\347\201\257/note-2021-06-11.md" @@ -0,0 +1,19 @@ +# 安装vue脚手架 ++ 安装vue前yarn是否已安装 ++ 若没有安装,利用淘宝镜像快速安装yarn ++ yarn的速度要比npm的快很多 +## 终端输入vue 可以查看vue是否安装完成 +1. npm i -g yarn +2. yarn config set registry http://registry.npm.taobao.org +3. yarn global add @vue/cli +4. 设置添加系统环境变量Path C:\Users\Administrator\AppData\Local\Yarn\bin ++ 注意 上面那个是机房的地址 本机的地址是C:\Users\陆万灯\AppData\Local\Yarn\bin ++ 不知道地址可以在输入 yarn global bin 来查看 +5. 进入其它盘 创建文件夹 + 1. 其它盘: + 2. mkdir 文件名 + 3. cd 文件名 按tab可以直接出来 + 4. vue create 项目名 + 5. 选vue2 回车 在选yarn 回车 + 6. 打开文件管理 用vscode打开 + 7. 终端输入yarn serve 注意 这是serve不是server \ No newline at end of file diff --git "a/\351\231\206\344\270\207\347\201\257/note-2021-06-12.md" "b/\351\231\206\344\270\207\347\201\257/note-2021-06-12.md" new file mode 100644 index 0000000000000000000000000000000000000000..60fd776d8a05e5dae9ec75fbedd9cb15bc3aad43 --- /dev/null +++ "b/\351\231\206\344\270\207\347\201\257/note-2021-06-12.md" @@ -0,0 +1,33 @@ +# 单文件组件 +## 创建组件(脚手架中) ++ 在脚手架中,创建一个组件 ++ 就是在components中创建一个文件类型为.vue的文件,如 HellloWorld.vue ++ .vue文件就称为单文件组件,是Vue.js自定义的一种文件格式 ++ 一个.vue文件就是一个单独的组件,在文件内封装了组件相关的代码:html、css、js ++ .vue文件由三部分组成:`