diff --git a/README.md b/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/img/2-step1.png b/img/2-step1.png new file mode 100644 index 0000000..ddcc903 Binary files /dev/null and b/img/2-step1.png differ diff --git a/img/2-stpe2.png b/img/2-stpe2.png new file mode 100644 index 0000000..70e3bac Binary files /dev/null and b/img/2-stpe2.png differ diff --git a/img/life.png b/img/life.png new file mode 100644 index 0000000..f12a2b6 Binary files /dev/null and b/img/life.png differ diff --git a/img/refs.png b/img/refs.png new file mode 100644 index 0000000..f141bb4 Binary files /dev/null and b/img/refs.png differ diff --git a/img/refs1.png b/img/refs1.png new file mode 100644 index 0000000..f1ea6ba Binary files /dev/null and b/img/refs1.png differ diff --git a/img/step-3.png b/img/step-3.png new file mode 100644 index 0000000..596a9d7 Binary files /dev/null and b/img/step-3.png differ diff --git a/img/step1.png b/img/step1.png new file mode 100644 index 0000000..ec9706b Binary files /dev/null and b/img/step1.png differ diff --git a/img/step2.png b/img/step2.png new file mode 100644 index 0000000..be1f3eb Binary files /dev/null and b/img/step2.png differ diff --git a/img/step3.png b/img/step3.png new file mode 100644 index 0000000..d510b75 Binary files /dev/null and b/img/step3.png differ diff --git a/img/step4.png b/img/step4.png new file mode 100644 index 0000000..e899b57 Binary files /dev/null and b/img/step4.png differ diff --git a/img/step5.png b/img/step5.png new file mode 100644 index 0000000..be87f2f Binary files /dev/null and b/img/step5.png differ diff --git a/img/step6.png b/img/step6.png new file mode 100644 index 0000000..07b46ef Binary files /dev/null and b/img/step6.png differ diff --git a/img/step7.png b/img/step7.png new file mode 100644 index 0000000..cc19b03 Binary files /dev/null and b/img/step7.png differ diff --git a/img/step8.png b/img/step8.png new file mode 100644 index 0000000..83c0cbe Binary files /dev/null and b/img/step8.png differ diff --git a/img/step9.png b/img/step9.png new file mode 100644 index 0000000..648b6ec Binary files /dev/null and b/img/step9.png differ diff --git a/img/ui-1.png b/img/ui-1.png new file mode 100644 index 0000000..3975c7b Binary files /dev/null and b/img/ui-1.png differ diff --git a/img/ui-2.png b/img/ui-2.png new file mode 100644 index 0000000..9dcb42a Binary files /dev/null and b/img/ui-2.png differ diff --git a/img/ui-3.png b/img/ui-3.png new file mode 100644 index 0000000..596a9d7 Binary files /dev/null and b/img/ui-3.png differ diff --git a/vue搭建.md b/vue搭建.md new file mode 100644 index 0000000..6349193 --- /dev/null +++ b/vue搭建.md @@ -0,0 +1,478 @@ +# vue知识分享 + +## 创建一个包含babel和eslint工程化项目 + +### 环境准备 +1. 安装node(自带npm,node版本14以上) +2. 在任意文件夹中打开终端(便捷打开终端方式:在文件夹地址中输入cmd+ener键即可) +3. 安装脚手架(vue-cli 5.0.8版本为例) + 1. npm i -g @vue/cli 5.0.8 (-g 全局安装) + 2. vue -V (查看脚手架版本,检测是否安装成功) + +### 操作步骤 +1. 利用脚手架搭建项目:目前提供了两种方式, + + 1. vue ui (界面化选配搭建) + 1. 进入要搭建项目的目录打开终端输入:vue ui 将自动打开一个创建页面 + 2. +  +  + + + 2. 使用vue create 命令方式搭建 + 1. 进入要搭建项目的目录打开终端输入:vue create vue-cli-project + 2. 选中默认模板 Default([Vue 2] babel, eslint) + + + +### 项目目录结构 +```bash +|-- HELLO_WORLD 项目名称 + |-- node_modules 依赖文件 + |-- public 静态资源 + | |-- favicon.ico 页面tab图标 + | |-- index.html 挂载的页面 +|-- src 主要开发的源码 + |-- App.vue 根组件 + |-- main.js 整个项目的入口,引入依赖包、默认页面样式等 + |-- assets 资源文件 + | |-- logo.png + |-- components 公共组件 + |-- HelloWorld.vue + |-- .browserslistrc 浏览器约定(可写到package.json中去) + |-- .eslintrc.js eslint配置(可写到package.json中去) + |-- .gitignore 提交忽略文件配置 + |-- babel.config.js babel配置文件(使es6+向后兼容适配浏览器的js环境) + |-- jsconfig.json 文件提示配置 + |-- package-lock.json 版本锁定文件 + |-- package.json 版本信息 + |-- README.md + |-- vue.config.js webpack相关配置(vue.config.js: https://cli.vuejs.org/zh/config/#vue-config-js) +``` + +## 二:初步应用vue + +### vue生命周期 +> **vue生命周期是什么?** +> + vue生命周期是指vue对象从创建到销毁的过程。也就是vue对象从开始创建、初始化数据、编译模板、挂载Dom、渲染→更新→渲染、卸载这一系列过程。其作用是在vue生命周期的不同阶段通过对应的钩子函数来实现组件数据管理和DOM渲染两大重要功能。 + + + + +> **生命周期钩子有那些?** +> + 1. beforeCreate(创建前) + 2. created (创建后,该时间能拿到data中数据了) + 3. beforeMount (载入前) + 4. mounted (载入后,该时间能拿到dom元素) + 5. beforeUpdate (更新前) + 6. updated (更新后) + 7. beforeDestroy( 销毁前) + 8. destroyed (销毁后) + +生命周期钩子使用 + +应用场景:初次加载组件触发了beforeCreate、created、beforeMount、mounted四个钩子函数,我们可以在created函数中操作数据,在mounted中操作dom元素。 +1. 在App.vue中添加beforeCreate、created、beforeMount、mounted四个钩子函数。 +2. 启动项目,打开网页F12查看console控制台信息。 + + 应用代码 + + ```bash + + + + + + + + #在src/App.vue中引用GetValue.vue。App.vue中引用代码 + + + + + + + + + ``` + + +### vue中属性绑定、事件绑定及v-model +- 属性绑定(v-bind: 简写:):主要是将data中的数据绑定到对应标签上,实现data中数据->标签数据上的传递。 + + + + 具体案例代码 + + ```bash + #在src/components中新建DataTest.vue内容如下,在App.vue中引入。项目启动后input中数据初始为'这是data中定义的数据' + + + + + + + + ``` + + +- 事件绑定(v-on: 简写@):主要是将methods中的函数绑定到对应标签上,可实现标签中数据->data数据上的传递。 + + + 具体案例代码 + + ```bash + #在src/components/DataTest.vue继续添加代码如下,项目启动后打开页面,在input中输入的数据会传递到data中input中,然后在h1体现 + + + 显示的是data中input的数据:{{input}} + + + + + + ``` + + +- v-model是属性绑定和函数绑定的语法糖 + ```bash + #下面两行代码在input标签下是等价的 + + + ``` + + +### 取值方式 +1. 原生方式取值方式主要是通过document上的方法进行取值的。例如 + + ```bash + document.querySelector() + document.getElementById() + document.getElementsByClassName() + ``` + +2. vue中取值方式 + + vue中普遍的取值两种方式: + - 通过$refs和ref,注册引用信息(主要用来获取子组件信息) + - data中定义,绑定标签,组件实列中通过this.xx引用 + + + 两种方式取值的具体案例代码 + + ```bash + #通过getVaule触发在F12 console控制台能发现输出的值是一样的 + + + {{title}} + + 获取值 + + + + + ``` + + + +### 父子组件中的传值 + +应用场景:子组件需要父组件传递数据进行数据的展示,而子组件功能又要对接受的数据进行处理更新,这个时候就需要父子组件传值。 + +1. 父传子数据 + + 父传子数据代码 + + ```bash + #在src/components新建Parent.vue,child.vue两个父子组件 + #Parent.vue + + + #1.挂载title + + + + + + + #child.vue + + #3.使用传递的数据 + {{title}} + + + + + ``` + + +2. 子传父数据 + + + 子传父数据代码 + + ```bash + #在src/components新建Parent.vue,child.vue两个父子组件 + #Parent.vue + + + #2.挂载函数 + + + + + + #child.vue + + 点击子组件修改数据:{{title}} + + + + + ``` + +2. 父子传值整合 + + + 父子传值整合代码 + + ```bash + #在src/components新建Parent.vue,child.vue两个父子组件 + #Parent.vue + + + 点击重置父组件title:{{title}} + #1. 绑定title,updateTiTle + + + + + + #child.vue + + #3.使用title + 点击子组件修改数据:{{title}} + + + + ``` + \ No newline at end of file