一、数据要求
(1) fetch
为什么要用?
XMLHttpRequest是一个设计粗糙的API,配置和调用方式非常混乱。
此外,基于事件的异步模型不容易写。
兼容性差,这是W3C的标准,将来实现兼容性的话,一定会发生大火
//getfetch () * ).then ) RES=RES.JSON ) )、then ) RES={console.log(RES ) fetch ) (* ) ) then ) ) headers : { ' content (type ' : ' application/x (www (表单(urlencoded (},fetch((/users ),{method: ) body : JSON.stringify ({ name : ' kerwin ',age:100 } ) }.then () RES=RES.JSON () ) ).then ) RES
注意:
默认情况下,Fetch请求没有cookie,并且必须设置Fetch(URL,{credentials: )
' include'} )
)1) axios
请注意,axios外部封装了数据。
脚本//axios请求,第三方库newvue({El:'#box ),data: ) datalist:(},methods : { BTH (} ) 这是最外层) /箭头函数axios.get('./JSON/test.JSON ' ).then ) ) RES=) TSON,err={console.log(err ); }}}}}/script2,计算属性
复杂的逻辑,模板很难维护
)1)基础实例
)2)缓存vs方法的计算
-计算属性根据它们的依赖关系进行缓存。
-仅当相关依赖关系发生更改时,才会重新评估计算属性
(3)计算属性VSwatch
- v模型
以下是实现模糊搜索的计算属性
divid=' box ' input type=' text ' v-model=' my text ' /! - input type=' text ' @ input=' handle input '//-- ulliv-for=' dataingetmydatalist ' { data } }/Li/ul/divs crist 盒)、data: ) mytext: )、data lisst computed 3360 { get my datalist (} { return this.datalist.filter (item=item.)