怎么做安居客网站,wordpress 函数文件,济南网站建设seo优化,wordpress安装与使用说明一、文章内容概括
1.生命周期
生命周期介绍生命周期的四个阶段生命周期钩子声明周期案例
2.工程化开发入门
工程化开发和脚手架项目运行流程组件化组件注册
二、Vue生命周期
思考#xff1a;什么时候可以发送初始化渲染请求#xff1f;#xff08;越早越好#xff09…一、文章内容概括
1.生命周期
生命周期介绍生命周期的四个阶段生命周期钩子声明周期案例
2.工程化开发入门
工程化开发和脚手架项目运行流程组件化组件注册
二、Vue生命周期
思考什么时候可以发送初始化渲染请求越早越好什么时候可以开始操作dom至少dom得渲染出来
Vue生命周期就是一个Vue实例从创建 到 销毁 的整个过程。
生命周期四个阶段① 创建 ② 挂载 ③ 更新 ④ 销毁
1.创建阶段创建响应式数据
2.挂载阶段渲染模板
3.更新阶段修改数据更新视图
4.销毁阶段销毁Vue实例 三、Vue生命周期钩子
Vue生命周期过程中会自动运行一些函数被称为【生命周期钩子】→ 让开发者可以在【特定阶段】运行自己的代码 !DOCTYPE html
html langen
headmeta charsetUTF-8meta http-equivX-UA-Compatible contentIEedgemeta nameviewport contentwidthdevice-width, initial-scale1.0titleDocument/title
/head
bodydiv idapph3{{ title }}/h3divbutton clickcount---/buttonspan{{ count }}/spanbutton clickcount/button/div/divscript srchttps://cdn.jsdelivr.net/npm/vue2/dist/vue.js/scriptscriptconst app new Vue({el: #app,data: {count: 100,title: 计数器},// 1. 创建阶段准备数据beforeCreate () {console.log(beforeCreate 响应式数据准备好之前, this.count)// 此时this.count为undefind},created () {console.log(created 响应式数据准备好之后, this.count)// this.数据名 请求回来的数据// 可以开始发送初始化渲染的请求了},// 2. 挂载阶段渲染模板beforeMount () {// 结果{{ title }}console.log(beforeMount 模板渲染之前, document.querySelector(h3).innerHTML)},mounted () {// 结果计数器console.log(mounted 模板渲染之后, document.querySelector(h3).innerHTML)// 可以开始操作dom了},// 3. 更新阶段(修改数据 → 更新视图)beforeUpdate () {console.log(beforeUpdate 数据修改了视图还没更新, document.querySelector(span).innerHTML)},updated () {console.log(updated 数据修改了视图已经更新, document.querySelector(span).innerHTML)},// 4. 卸载阶段beforeDestroy () {console.log(beforeDestroy, 卸载前)console.log(清除掉一些Vue以外的资源占用定时器延时器...)},destroyed () {console.log(destroyed卸载后)}})/script
/body
/html四、生命周期钩子小案例
1.在created中发送数据
!DOCTYPE html
html langenheadmeta charsetUTF-8meta http-equivX-UA-Compatible contentIEedgemeta nameviewport contentwidthdevice-width, initial-scale1.0titleDocument/titlestyle* {margin: 0;padding: 0;list-style: none;}.news {display: flex;height: 120px;width: 600px;margin: 0 auto;padding: 20px 0;cursor: pointer;}.news .left {flex: 1;display: flex;flex-direction: column;justify-content: space-between;padding-right: 10px;}.news .left .title {font-size: 20px;}.news .left .info {color: #999999;}.news .left .info span {margin-right: 20px;}.news .right {width: 160px;height: 120px;}.news .right img {width: 100%;height: 100%;object-fit: cover;}/style
/headbodydiv idappulli v-for(item, index) in list :keyitem.id classnewsdiv classleftdiv classtitle{{ item.title }}/divdiv classinfospan{{ item.source }}/spanspan{{ item.time }}/span/div/divdiv classrightimg :srcitem.img alt/div/li/ul/divscript srchttps://cdn.jsdelivr.net/npm/vue2/dist/vue.js/scriptscript srchttps://cdn.jsdelivr.net/npm/axios/dist/axios.min.js/scriptscript// 接口地址http://hmajax.itheima.net/api/news// 请求方式getconst app new Vue({el: #app,data: {list: []},async created() {// 1. 发送请求获取数据const res await axios.get(http://hmajax.itheima.net/api/news)// 2. 更新到 list 中用于页面渲染 v-forthis.list res.data.data}})/script
/body/html2.在mounted中获取焦点
!DOCTYPE html
html langzh-CNheadmeta charsetUTF-8meta http-equivX-UA-Compatible contentIEedgemeta nameviewport contentwidthdevice-width, initial-scale1.0title示例-获取焦点/title!-- 初始化样式 --link relstylesheet hrefhttps://cdn.jsdelivr.net/npm/reset.css2.0.2/reset.min.css!-- 核心样式 --stylehtml,body {height: 100%;}.search-container {position: absolute;top: 30%;left: 50%;transform: translate(-50%, -50%);text-align: center;}.search-container .search-box {display: flex;}.search-container img {margin-bottom: 30px;}.search-container .search-box input {width: 512px;height: 16px;padding: 12px 16px;font-size: 16px;margin: 0;vertical-align: top;outline: 0;box-shadow: none;border-radius: 10px 0 0 10px;border: 2px solid #c4c7ce;background: #fff;color: #222;overflow: hidden;box-sizing: content-box;-webkit-tap-highlight-color: transparent;}.search-container .search-box button {cursor: pointer;width: 112px;height: 44px;line-height: 41px;line-height: 42px;background-color: #ad2a27;border-radius: 0 10px 10px 0;font-size: 17px;box-shadow: none;font-weight: 400;border: 0;outline: 0;letter-spacing: normal;color: white;}body {background: no-repeat center /cover;background-color: #edf0f5;}/style
/headbodydiv classcontainer idappdiv classsearch-containerimg srchttps://www.itheima.com/images/logo.png altdiv classsearch-boxinput typetext v-modelwords idinpbutton搜索一下/button/div/div/divscript srchttps://cdn.jsdelivr.net/npm/vue2/dist/vue.js/scriptscriptconst app new Vue({el: #app,data: {words: },// 核心思路// 1. 等input框渲染出来 mounted 钩子// 2. 让input框获取焦点 inp.focus()mounted() {document.querySelector(#inp).focus()}})/script/body/html五、案例-小黑记账清单
1.需求图示 2.需求分析
1.基本渲染
2.添加功能
3.删除功能
4.饼图渲染
3.思路分析
1.基本渲染
立刻发送请求获取数据 created拿到数据存到data的响应式数据中结合数据进行渲染 v-for消费统计 — 计算属性
2.添加功能
收集表单数据 v-model使用指令修饰符处理数据给添加按钮注册点击事件对输入的内容做非空判断发送请求请求成功后对文本框内容进行清空重新渲染列表
3.删除功能
注册点击事件获取当前行的id根据id发送删除请求需要重新渲染
4.饼图渲染
初始化一个饼图 echarts.init(dom) mounted钩子中渲染根据数据试试更新饼图 echarts.setOptions({…})
4.代码准备
!DOCTYPE html
html langenheadmeta charsetUTF-8 /meta nameviewport contentwidthdevice-width, initial-scale1.0 /titleDocument/title!-- CSS only --link relstylesheet hrefhttps://cdn.jsdelivr.net/npm/bootstrap5.1.3/dist/css/bootstrap.min.css /style.red {color: red !important;}.search {width: 300px;margin: 20px 0;}.my-form {display: flex;margin: 20px 0;}.my-form input {flex: 1;margin-right: 20px;}.table :not(:first-child) {border-top: none;}.contain {display: flex;padding: 10px;}.list-box {flex: 1;padding: 0 30px;}.list-box a {text-decoration: none;}.echarts-box {width: 600px;height: 400px;padding: 30px;margin: 0 auto;border: 1px solid #ccc;}tfoot {font-weight: bold;}media screen and (max-width: 1000px) {.contain {flex-wrap: wrap;}.list-box {width: 100%;}.echarts-box {margin-top: 30px;}}/style
/headbodydiv idappdiv classcontain!-- 左侧列表 --div classlist-box!-- 添加资产 --form classmy-forminput v-model.trimname typetext classform-control placeholder消费名称 /input v-model.numberprice typetext classform-control placeholder消费价格 /button clickadd typebutton classbtn btn-primary添加账单/button/formtable classtable table-hovertheadtrth编号/thth消费名称/thth消费价格/thth操作/th/tr/theadtbodytr v-for(item, index) in list :keyitem.idtd{{ index 1 }}/tdtd{{ item.name }}/tdtd :class{ red: item.price 500 }{{ item.price.toFixed(2) }}/tdtda clickdel(item.id) hrefjavascript:;删除/a/td/tr/tbodytfoottrtd colspan4消费总计 {{ totalPrice.toFixed(2) }}/td/tr/tfoot/table/div!-- 右侧图表 --div classecharts-box idmain/div/div/divscript srchttps://cdn.jsdelivr.net/npm/echarts5.4.0/dist/echarts.min.js/scriptscript srchttps://cdn.jsdelivr.net/npm/vue2/dist/vue.js/scriptscript srchttps://cdn.jsdelivr.net/npm/axios/dist/axios.min.js/scriptscript/*** 接口文档地址* https://www.apifox.cn/apidoc/shared-24459455-ebb1-4fdc-8df8-0aff8dc317a8/api-53371058* * 功能需求* 1. 基本渲染* (1) 立刻发送请求获取数据 created* (2) 拿到数据存到data的响应式数据中* (3) 结合数据进行渲染 v-for* (4) 消费统计 计算属性* 2. 添加功能* (1) 收集表单数据 v-model* (2) 给添加按钮注册点击事件发送添加请求* (3) 需要重新渲染* 3. 删除功能* (1) 注册点击事件传参传 id* (2) 根据 id 发送删除请求* (3) 需要重新渲染* 4. 饼图渲染* (1) 初始化一个饼图 echarts.init(dom) mounted钩子实现* (2) 根据数据实时更新饼图 echarts.setOption({ ... })*/const app new Vue({el: #app,data: {list: [],name: ,price: },computed: {totalPrice() {return this.list.reduce((sum, item) sum item.price, 0)}},created() {// const res await axios.get(https://applet-base-api-t.itheima.net/bill, {// params: {// creator: 小黑// }// })// this.list res.data.datathis.getList()},mounted() {this.myChart echarts.init(document.querySelector(#main))this.myChart.setOption({// 大标题title: {text: 消费账单列表,left: center},// 提示框tooltip: {trigger: item},// 图例legend: {orient: vertical,left: left},// 数据项series: [{name: 消费账单,type: pie,radius: 50%, // 半径data: [// { value: 1048, name: 球鞋 },// { value: 735, name: 防晒霜 }],emphasis: {itemStyle: {shadowBlur: 10,shadowOffsetX: 0,shadowColor: rgba(0, 0, 0, 0.5)}}}]})},methods: {async getList() {const res await axios.get(https://applet-base-api-t.itheima.net/bill, {params: {creator: 小黑}})this.list res.data.data// 更新图表this.myChart.setOption({// 数据项series: [{// data: [// { value: 1048, name: 球鞋 },// { value: 735, name: 防晒霜 }// ]data: this.list.map(item ({ value: item.price, name: item.name }))}]})},async add() {if (!this.name) {alert(请输入消费名称)return}if (typeof this.price ! number) {alert(请输入正确的消费价格)return}// 发送添加请求const res await axios.post(https://applet-base-api-t.itheima.net/bill, {creator: 小黑,name: this.name,price: this.price})// 重新渲染一次this.getList()this.name this.price },async del(id) {// 根据 id 发送删除请求const res await axios.delete(https://applet-base-api-t.itheima.net/bill/${id})// 重新渲染this.getList()}}})/script
/body/html六、工程化开发和脚手架
1.开发Vue的两种方式
核心包传统开发模式基于html / css / js 文件直接引入核心包开发 Vue。工程化开发模式基于构建工具例如webpack的环境中开发Vue。 工程化开发模式优点
提高编码效率比如使用JS新语法、Less/Sass、Typescript等通过webpack都可以编译成浏览器识别的ES3/ES5/CSS等
工程化开发模式问题
webpack配置不简单雷同的基础配置缺乏统一的标准
为了解决以上问题所以我们需要一个工具生成标准化的配置
2.脚手架Vue CLI
基本介绍
Vue CLI 是Vue官方提供的一个全局命令工具
可以帮助我们快速创建一个开发Vue项目的标准化基础架子。【集成了webpack配置】
好处
开箱即用零配置内置babel等工具标准化的webpack配置
使用步骤
全局安装只需安装一次即可 yarn global add vue/cli 或者 npm i vue/cli -g查看vue/cli版本 vue --version创建项目架子vue create project-name(项目名不能使用中文)启动项目yarn serve 或者 npm run serve(命令不固定找package.json)
七、项目目录介绍和运行流程
1.项目目录介绍 虽然脚手架中的文件有很多目前咱们只需人事三个文件即可
main.js 入口文件App.vue App根组件index.html 模板文件
2.运行流程 index.html
!DOCTYPE html
html langheadmeta charsetutf-8meta http-equivX-UA-Compatible contentIEedgemeta nameviewport contentwidthdevice-width,initial-scale1.0link relicon href% BASE_URL %favicon.icotitle% htmlWebpackPlugin.options.title %/title/headbody!-- 兼容给不支持js的浏览器一个提示 --noscriptstrongWere sorry but % htmlWebpackPlugin.options.title % doesnt work properly without JavaScript enabled. Please enable it to continue./strong/noscript!-- Vue所管理的容器将来创建结构动态渲染这个容器 --div idapp!-- 工程化开发模式中这里不再直接编写模板语法通过 App.vue 提供结构渲染 --/div!-- built files will be auto injected --/body
/html
main.js
// 文件核心作用导入App.vue基于App.vue创建结构渲染index.html
// 1. 导入 Vue 核心包
import Vue from vue// 2. 导入 App.vue 根组件
import App from ./App.vue// 提示当前处于什么环境 (生产环境 / 开发环境)
Vue.config.productionTip false// 3. Vue实例化提供render方法 → 基于App.vue创建结构渲染index.html
new Vue({// el: #app, 作用和$mount(选择器)作用一致用于指定Vue所管理容器// render: h h(App),render: (createElement) {// 基于App创建元素结构return createElement(App)}
}).$mount(#app)
八、组件化开发
组件化一个页面可以拆分成一个个组件每个组件有着自己独立的结构、样式、行为。
好处便于维护利于复用 → 提升开发效率。
组件分类普通组件、根组件。
比如下面这个页面可以把所有的代码都写在一个页面中但是这样显得代码比较混乱难易维护。咱们可以按模块进行组件划分 总结
组件化的好处是什么
组件的分类
九、根组件 App.vue
1.根组件介绍
整个应用最上层的组件包裹所有普通小组件 2.组件是由三部分构成
语法高亮插件 三部分构成 template结构 有且只能一个根元素script: js逻辑style 样式 (可支持less需要装包) 让组件支持less 1 style标签lang“less” 开启less功能 2 装包: yarn add less less-loader -D 或者npm i less less-loader -D -D 开发依赖–save-dev的简写
3.总结
App组件包含哪三部分
十、普通组件的注册使用-局部注册
1.特点
只能在注册的组件内使用
2.步骤
创建.vue文件三个组成部分在使用的组件内先导入再注册最后使用
3.使用方式
当成html标签使用即可 组件名/组件名
4.注意
组件名规范 — 大驼峰命名法 如 HmHeader
5.语法 // 导入需要注册的组件
import 组件对象 from .vue文件路径
import HmHeader from ./components/HmHeaderexport default { // 局部注册components: {组件名: 组件对象,HmHeader:HmHeaer,HmHeader}
}6.练习
在App组件中完成以下练习。在App.vue中使用组件的方式完成下面布局 HmHeader.vue
templatediv classhm-header我是hm-header/div
/templatescript
export default {}
/scriptstyle
.hm-header {height: 100px;line-height: 100px;text-align: center;font-size: 30px;background-color: #8064a2;color: white;
}
/styleHmMain.vue
templatediv classhm-main我是hm-main/div
/templatescript
export default {}
/scriptstyle
.hm-main {height: 400px;line-height: 400px;text-align: center;font-size: 30px;background-color: #f79646;color: white;margin: 20px 0;
}
/styleHmFooter.vue
templatediv classhm-footer我是hm-footer/div
/templatescript
export default {}
/scriptstyle
.hm-footer {height: 100px;line-height: 100px;text-align: center;font-size: 30px;background-color: #4f81bd;color: white;
}
/styleApp.vue
templatediv classApp!-- 头部组件 --HmHeader/HmHeader!-- 主体组件 --HmMain/HmMain!-- 底部组件 --HmFooter/HmFooter!-- 如果 HmFooter tab 出不来 → 需要配置 vscode设置中搜索 trigger on tab → 勾上--/div
/templatescript
import HmHeader from ./components/HmHeader.vue
import HmMain from ./components/HmMain.vue
import HmFooter from ./components/HmFooter.vue
export default {components: {// 组件名: 组件对象HmHeader: HmHeader,HmMain,HmFooter}
}
/scriptstyle
.App {width: 600px;height: 700px;background-color: #87ceeb;margin: 0 auto;padding: 20px;
}
/style7.总结
A组件内部注册的局部组件能在B组件使用吗局部注册组件的步骤是什么使用组件时 应该按照什么命名法
十一、普通组件的注册使用-全局注册
1.特点
全局注册的组件在项目的任何组件中都能使用
2.步骤
创建.vue组件三个组成部分main.js中进行全局注册
3.使用方式
当成HTML标签直接使用 组件名/组件名 4.注意
组件名规范 — 大驼峰命名法 如 HmHeader
5.语法
Vue.component(‘组件名’, 组件对象)
例
// 导入需要全局注册的组件
import HmButton from ./components/HmButton
Vue.component(HmButton, HmButton)6.练习
在以下3个局部组件中是展示一个通用按钮 HmButton.vue
templatebutton classhm-button通用按钮/button
/templatescript
export default {}
/scriptstyle
.hm-button {height: 50px;line-height: 50px;padding: 0 20px;background-color: #3bae56;border-radius: 5px;color: white;border: none;vertical-align: middle;cursor: pointer;
}
/stylemain.js
import Vue from vue
import App from ./App.vue
// 编写导入的代码往代码的顶部编写(规范)
import HmButton from ./components/HmButton.vueVue.config.productionTip false// 进行全局注册 → 在所有的组件范围内都能直接使用
// Vue.component(组件名组件对象)
Vue.component(HmButton, HmButton)new Vue({render: h h(App),
}).$mount(#app)
在其中某个组件中使用比如HmMain.vue当成HTML标签直接使用
templatediv classhm-main我是hm-mainHmButton/HmButton/div
/templatescript
export default {};
/scriptstyle
.hm-main {height: 400px;line-height: 400px;text-align: center;font-size: 30px;background-color: #f79646;color: white;margin: 20px 0;
}
/style7.总结
1.全局注册组件应该在哪个文件中注册以及语法是什么
2.全局组件在项目中的任何一个组件中可不可以使用