网站建设工作量评估报价表,河北住房和城乡建设厅网站6,什么是网络营销定价的特点,上土巴兔装修土巴兔装修1 条件渲染 v-show v-if 
使用template可以使其里面的内容在html的结构中不变。条件渲染#xff1a; 
v-if 1#xff09;v-if“表达式” 2#xff09;v-else-if“表达式” 3#xff09;v-else {} 适用于#xff1a;切换频率较低的场景。特点#xff1a;不展示的DOM元素直…1 条件渲染 v-show v-if 
使用template可以使其里面的内容在html的结构中不变。条件渲染 
v-if 1v-if“表达式” 2v-else-if“表达式” 3v-else {} 适用于切换频率较低的场景。特点不展示的DOM元素直接被移除。注意v-if可以和v-else-if、v-else一起使用但要求结构不能被“打断”。v-show 写法v-show“表达式” 适用于切换频率较高的场景。特点不展示的DOM元素未被移除仅仅是使用样式隐藏掉。备注使用v-if时元素可能无法获取到而使用v-show一定可以获取到 
!DOCTYPE html
html langen
headmeta charsetUTF-8meta http-equivX-UA-Compatible contentIEedgemeta nameviewport contentwidthdevice-width, initial-scale1.0title/titlescript typetext/javascript srchttps://cdn.bootcdn.net/ajax/libs/vue/2.6.1/vue.js/script
/head
body
div idconditional-rendering!-- 使用v-show做条件渲染 切换频率高--!--    h1 v-showjudgehello {{ name }}/h1--!-- 使用v-if做条件渲染 切换频率低--!--    h1 v-ifjudgehello {{ name }}/h1--h2当前的n值是:{{ n }}/h2button clickn点我n1/button!-- v-if和v-else-if --div v-ifn  1Angular/divdiv v-else-ifn  2React/divdiv v-else-ifn  3Vue/divdiv v-elseother/div!-- v-if与template结合 --template v-ifn  1h2hello-zhaoshuai-lc/h2/template
/divscript typetext/javascriptVue.config.productionTip  falsenew Vue({el: #conditional-rendering,data: {name: zhaoshuai-lcinspur.com,judge: false,n: 1}})
/script
/body
/html2 列表渲染 v-for 
用于展示列表数据语法v-for“(item,index) in xxx” :key“yyy”可遍历数组、对象、字符串用的很少、指定次数用的很少 
!DOCTYPE html
html langen
headmeta charsetUTF-8titleTitle/titlescript typetext/javascript srchttps://cdn.bootcdn.net/ajax/libs/vue/2.6.1/vue.js/script
/head
body
div idv-forulli v-foritem in personList :keyitem.id{{ item.name }} - {{ item.age }}/li/ul
/div
script typetext/javascriptnew Vue({el: #v-for,data: {personList: [{id: 1001, name: zhaoshuai-la, age: 101},{id: 1002, name: zhaoshuai-lb, age: 102},{id: 1003, name: zhaoshuai-lc, age: 103}]}})
/script
/body
/htmlulli v-for(a, b) in personList{{ a }} - {{ b }}/li/ul上面的key可以做一个替换 ulli v-for(item, index) in personList :keyindex{{ item.name }} - {{ item.age }}/li/ulin 也可以替换为 of: ulli v-for(item, index) of personList :keyindex{{ item.name }} - {{ item.age }}/li/ul除了数组还可以遍历对象 
body
div idv-forulli v-for(value, key) of car :keykey{{ key }} - {{ value }}/li/ul/div
script typetext/javascriptnew Vue({el: #v-for,data: {car: {name: 奥迪A8,price: 70万,color: 黑色}}})
/script
/body
/html 测试遍历字符串 ulli v-for(char, index) of str :keyindex{{ index }} - {{ char }}/li/ul
str: hello3 这里对于列表渲染的key的原理做一个说明 
body
div idv-forbutton click.onceadd添加一个 zhaoshuai-ld/buttonulli v-for(item, index) of personList :keyindex{{ item.name }} - {{ item.age }}/li/ul/div
script typetext/javascriptnew Vue({el: #v-for,data: {personList: [{id: 1001, name: zhaoshuai-la, age: 101},{id: 1002, name: zhaoshuai-lb, age: 102},{id: 1003, name: zhaoshuai-lc, age: 103}]},methods: {add() {let person  {id: 1004, name: zhaoshuai-ld, age: 104}this.personList.unshift(person)}}})
/script
/body
/html 看似没有问题其实问题很大如下遍历列表时key的作用index作为key 
body
div idv-forbutton click.onceadd添加一个 zhaoshuai-ld/buttonulli v-for(item, index) of personList :keyindex{{ item.name }} - {{ item.age }}input typetext/li/ul/div
script typetext/javascriptnew Vue({el: #v-for,data: {personList: [{id: 1001, name: zhaoshuai-la, age: 101},{id: 1002, name: zhaoshuai-lb, age: 102},{id: 1003, name: zhaoshuai-lc, age: 103}]},methods: {add() {let person  {id: 1004, name: zhaoshuai-ld, age: 104}this.personList.unshift(person)}}})
/script
/body
/html 遍历列表时key的作用id作为key ulli v-for(item, index) of personList :keyitem.id{{ item.name }} - {{ item.age }}input typetext/li/ul3.1 面试题react、Vue中的key有什么作用key的内部原理 
虚拟DOM中key的作用 key是虚拟DOM对象的标识当数据发生变化时Vue会根据【新数据】生成【新的虚拟DOM】随后Vue进行【新虚拟DOM】与【旧虚拟DOM】的差异比较比较规则如下 1旧虚拟DOM中找到了与新虚拟DOM相同的key 若虚拟DOM中内容没变直接使用之前的真实DOM若虚拟DOM中内容变了则生成新的真实DOM随后替换掉页面中之前的真实DOM2旧虚拟DOM中未找到与新虚拟DOM相同的key 
创建新的真实DOM随后渲染到页面用index作为key可能会引发的问题 
1若对数据进行逆序添加、逆序删除等破坏顺序操作会产生没有必要的真实DOM更新  界面效果没问题但效率低。 2如果结构中还包含输入类的DOM会产生错误DOM更新  界面有问题。 
开发中如何选择key 1最好使用每条数据的唯一标识作为key比如说id、手机号、身份证号、学号等唯一值。 2如果不存在对数据的逆序添加、逆序删除等破坏顺序操作仅用于渲染列表中用于展示使用index作为key是没有问题的。 
4 列表过滤 
4.1 用watch实现列表过滤 
!DOCTYPE html
html langen
headmeta charsetUTF-8titleTitle/titlescript typetext/javascript srchttps://cdn.bootcdn.net/ajax/libs/vue/2.6.1/vue.js/script
/head
body
div idv-forinput typetext placeholder请输入名字 v-modelkeyWorldulli v-for(item, index) of filterPersonList :keyitem.id{{ item.name }} - {{ item.age }}/li/ul
/div
script typetext/javascriptnew Vue({el: #v-for,data: {keyWorld: ,personList: [{id: 001, name: 马冬梅, age: 19, sex: 女},{id: 002, name: 周冬雨, age: 20, sex: 女},{id: 003, name: 周杰伦, age: 21, sex: 男},{id: 004, name: 温兆伦, age: 22, sex: 男}],filterPersonList: []},watch: {keyWorld: {immediate: true,handler(newValue, oldValue) {this.filterPersonList  this.personList.filter((item)  {return item.name.indexOf(newValue) ! -1})}}}})
/script
/body
/html4.2 用computed实现列表过滤 
!DOCTYPE html
html langen
headmeta charsetUTF-8titleTitle/titlescript typetext/javascript srchttps://cdn.bootcdn.net/ajax/libs/vue/2.6.1/vue.js/script
/head
body
div idv-forinput typetext placeholder请输入名字 v-modelkeyWorldulli v-for(item, index) of filterPersonList :keyitem.id{{ item.name }} - {{ item.age }}/li/ul/div
script typetext/javascriptnew Vue({el: #v-for,data: {keyWorld: ,personList: [{id: 001, name: 马冬梅, age: 19, sex: 女},{id: 002, name: 周冬雨, age: 20, sex: 女},{id: 003, name: 周杰伦, age: 21, sex: 男},{id: 004, name: 温兆伦, age: 22, sex: 男}]},computed: {filterPersonList() {return this.personList.filter((item)  {return item.name.indexOf(this.keyWorld) ! -1})}}})
/script
/body
/html 
5 列表排序 
!DOCTYPE html
html langen
headmeta charsetUTF-8titleTitle/titlescript typetext/javascript srchttps://cdn.bootcdn.net/ajax/libs/vue/2.6.1/vue.js/script
/head
body
div idv-forinput typetext placeholder请输入名字 v-modelkeyWorldbutton clicksortType  2升序/buttonbutton clicksortType  1降序/buttonbutton clicksortType  0原序/buttonulli v-for(item, index) of filterPersonList :keyitem.id{{ item.name }} - {{ item.age }}/li/ul/div
script typetext/javascriptnew Vue({el: #v-for,data: {keyWorld: ,sortType: 0, // 0-原顺序 1-降序 2-升序personList: [{id: 001, name: 马冬梅, age: 19, sex: 女},{id: 002, name: 周冬雨, age: 24, sex: 女},{id: 003, name: 周杰伦, age: 55, sex: 男},{id: 004, name: 温兆伦, age: 12, sex: 男}]},computed: {filterPersonList() {let filterList  this.personList.filter((item)  {return item.name.indexOf(this.keyWorld) ! -1})// 判断是否需要排序if (this.sortType) {filterList.sort((a, b)  {return this.sortType  1 ? b.age - a.age : a.age - b.age})}return filterList}}})
/script
/body
/html 文章转载自: http://www.morning.zpfqh.cn.gov.cn.zpfqh.cn http://www.morning.dpjtn.cn.gov.cn.dpjtn.cn http://www.morning.rhfbl.cn.gov.cn.rhfbl.cn http://www.morning.mzhhr.cn.gov.cn.mzhhr.cn http://www.morning.yyzgl.cn.gov.cn.yyzgl.cn http://www.morning.fqyxb.cn.gov.cn.fqyxb.cn http://www.morning.rjjjk.cn.gov.cn.rjjjk.cn http://www.morning.rryny.cn.gov.cn.rryny.cn http://www.morning.fypgl.cn.gov.cn.fypgl.cn http://www.morning.kggxj.cn.gov.cn.kggxj.cn http://www.morning.yckrm.cn.gov.cn.yckrm.cn http://www.morning.ynlpy.cn.gov.cn.ynlpy.cn http://www.morning.srcth.cn.gov.cn.srcth.cn http://www.morning.rykmf.cn.gov.cn.rykmf.cn http://www.morning.rfzzw.com.gov.cn.rfzzw.com http://www.morning.kjfsd.cn.gov.cn.kjfsd.cn http://www.morning.cnlmp.cn.gov.cn.cnlmp.cn http://www.morning.wqpm.cn.gov.cn.wqpm.cn http://www.morning.wmmtl.cn.gov.cn.wmmtl.cn http://www.morning.krzrg.cn.gov.cn.krzrg.cn http://www.morning.mywmb.cn.gov.cn.mywmb.cn http://www.morning.rrpsw.cn.gov.cn.rrpsw.cn http://www.morning.bmzxp.cn.gov.cn.bmzxp.cn http://www.morning.stxg.cn.gov.cn.stxg.cn http://www.morning.rdxnt.cn.gov.cn.rdxnt.cn http://www.morning.hhzdj.cn.gov.cn.hhzdj.cn http://www.morning.hhqjf.cn.gov.cn.hhqjf.cn http://www.morning.kqzrt.cn.gov.cn.kqzrt.cn http://www.morning.nysjb.cn.gov.cn.nysjb.cn http://www.morning.ryxbz.cn.gov.cn.ryxbz.cn http://www.morning.lfttb.cn.gov.cn.lfttb.cn http://www.morning.yxdrf.cn.gov.cn.yxdrf.cn http://www.morning.psyrz.cn.gov.cn.psyrz.cn http://www.morning.pxbky.cn.gov.cn.pxbky.cn http://www.morning.ranglue.com.gov.cn.ranglue.com http://www.morning.sglcg.cn.gov.cn.sglcg.cn http://www.morning.zlmbc.cn.gov.cn.zlmbc.cn http://www.morning.dnqliv.cn.gov.cn.dnqliv.cn http://www.morning.rjjys.cn.gov.cn.rjjys.cn http://www.morning.sqnrz.cn.gov.cn.sqnrz.cn http://www.morning.lqznq.cn.gov.cn.lqznq.cn http://www.morning.dswtz.cn.gov.cn.dswtz.cn http://www.morning.nkjkh.cn.gov.cn.nkjkh.cn http://www.morning.pgmyn.cn.gov.cn.pgmyn.cn http://www.morning.fndfn.cn.gov.cn.fndfn.cn http://www.morning.fhtmp.cn.gov.cn.fhtmp.cn http://www.morning.pznhn.cn.gov.cn.pznhn.cn http://www.morning.zwppm.cn.gov.cn.zwppm.cn http://www.morning.hqbnx.cn.gov.cn.hqbnx.cn http://www.morning.fxwkl.cn.gov.cn.fxwkl.cn http://www.morning.xflzm.cn.gov.cn.xflzm.cn http://www.morning.zljqb.cn.gov.cn.zljqb.cn http://www.morning.nwpnj.cn.gov.cn.nwpnj.cn http://www.morning.lwhsp.cn.gov.cn.lwhsp.cn http://www.morning.wwdlg.cn.gov.cn.wwdlg.cn http://www.morning.hsdhr.cn.gov.cn.hsdhr.cn http://www.morning.gcysq.cn.gov.cn.gcysq.cn http://www.morning.kxymr.cn.gov.cn.kxymr.cn http://www.morning.gkgr.cn.gov.cn.gkgr.cn http://www.morning.trjr.cn.gov.cn.trjr.cn http://www.morning.wcczg.cn.gov.cn.wcczg.cn http://www.morning.wztnh.cn.gov.cn.wztnh.cn http://www.morning.qhqgk.cn.gov.cn.qhqgk.cn http://www.morning.xqltq.cn.gov.cn.xqltq.cn http://www.morning.tfwg.cn.gov.cn.tfwg.cn http://www.morning.knczz.cn.gov.cn.knczz.cn http://www.morning.lpzyq.cn.gov.cn.lpzyq.cn http://www.morning.wnrcj.cn.gov.cn.wnrcj.cn http://www.morning.nwgkk.cn.gov.cn.nwgkk.cn http://www.morning.mjwnc.cn.gov.cn.mjwnc.cn http://www.morning.zxgzp.cn.gov.cn.zxgzp.cn http://www.morning.xqxrm.cn.gov.cn.xqxrm.cn http://www.morning.qyglt.cn.gov.cn.qyglt.cn http://www.morning.xnkb.cn.gov.cn.xnkb.cn http://www.morning.znqztgc.cn.gov.cn.znqztgc.cn http://www.morning.fdrwk.cn.gov.cn.fdrwk.cn http://www.morning.bswhr.cn.gov.cn.bswhr.cn http://www.morning.pslzp.cn.gov.cn.pslzp.cn http://www.morning.fwnqq.cn.gov.cn.fwnqq.cn http://www.morning.qllcp.cn.gov.cn.qllcp.cn