当前位置: 首页 > news >正文

旅游网站结构图泉州建设网站公司

旅游网站结构图,泉州建设网站公司,网页跳转链接怎么制作,医院网站建设运营方案日常开发记录-正确的prop传参#xff0c;reduce搭配promise的使用 1.正确的prop传参2.reduce搭配promise的使用 1.正确的prop传参 一般会的父组件传参子组件 //父组件 A :demodata.synctestData :listData.synctestData2/A data ()… 日常开发记录-正确的prop传参reduce搭配promise的使用 1.正确的prop传参2.reduce搭配promise的使用 1.正确的prop传参 一般会的父组件传参子组件 //父组件 A :demodata.synctestData :listData.synctestData2/A data () {return {testData: {content: ,textStyle: {fontsize: 14px,},},testData2: [{content: 11,textStyle: {fontsize: 14px,},},],}}, //子组件 el-input v-modeldemodata.content/el-input然后子组件v-model看着和使用起来是可以达到双向绑定的但是是不推荐这样改的。 //子组件 templatediv{{ demodata }}!-- 不要直接修改 props使用事件通知父组件更新 使用 .sync 修饰符或 v-model 实现双向绑定,这种感觉单个属性可以类似“监听”整个对象数组貌似不太行 --el-input :valuedemodata.content inputchangeInput/el-inputel-table :datalocalDatael-table-column propcontent label姓名/el-table-column/el-tableel-button clickadd添加/el-button/div /template script export default {props: {demodata: {type: Object,default: () { }},listData: {type: Array,default: () []}},data () {return {localData: [...this.listData]}},watch: {listData: {handler (newVal) {this.localData [...newVal]},deep: true}},mounted () {},methods: {changeInput (val) {this.$emit(update:demodata, {...this.demodata,content: val})}, add () {this.localData.push({ name: test })this.$emit(update:listData, [...this.localData])}} } /script还有种父组件v-model的写法 //父组件A v-modeltestData3/AtestData3: {content: ,textStyle: {fontsize: 14px,},},//子组件 templatediv{{ demodata }}el-input :valuedemodata.content inputupdateContent/el-input/div /template script export default {model: {prop: demodata,event: update:demodata},props: {demodata: {type: Object,default: () { }},},methods: {updateContent (val) {this.$emit(update:demodata, { ...this.demodata, content: val });}} } /script子组件的写法要注意model选项里的prop和event都是自定义的但是要一一对应。 在 Vue 2 中一个组件上默认只能使用一个 v-model。这是因为 v-model 在 Vue 2 中主要是作为语法糖用于简化父子组件间的双向数据绑定它默认绑定到子组件的 value 属性上并监听 input 事件除非通过 model 选项进行了自定义。 然而如果你需要在 Vue 2 中实现多个双向数据绑定你可以使用 .sync 修饰符作为替代方案。.sync 修饰符允许你绑定一个对象或多个属性并在子组件中通过触发特定格式的事件update:属性名来更新父组件中的数据。 2.reduce搭配promise的使用 logInOrder (urls) {const textPromises urls.map((url) {return fetch(url).then((response) response.json()) // 修改为 json() 因为返回的是 JSON 数据.then((data) JSON.stringify(data, null, 2)) // 格式化输出})console.log(log, textPromises)return textPromises.reduce((chain, textPromise) {console.log(chain, chain,textPromise, textPromise)return chain.then(() textPromise).then((text) {console.log(获取到的数据\n, text)console.log(------------------------)return text})}, Promise.resolve())},reduce里面的代码有点没太理解本来一般也少写特别是then(() textPromise)这没太看懂改下写法 logInOrder(urls) {const textPromises urls.map(url {return fetch(url).then(response response.json()).then(data JSON.stringify(data, null, 2));});return textPromises.reduce((chain, textPromise) {return chain.then(() {return textPromise.then(text {console.log(获取到的数据\n, text);console.log(------------------------);return text; });});}, Promise.resolve()); }现在看得清楚了多看一次的执行就是轮询调用promise.then。而且有return text和没有return text的每次chain也是不一样的。 //调用实例const a this.logInOrder([https://jsonplaceholder.typicode.com/posts/1,https://jsonplaceholder.typicode.com/posts/2,https://jsonplaceholder.typicode.com/posts/3,https://jsonplaceholder.typicode.com/posts/4,https://jsonplaceholder.typicode.com/posts/5])console.log(a, a)猜猜它的打印结果呢。 有点出乎我的意料。。。怎么也不会是这个结果嘛感觉。自己想的理想输出是先打印chain然后是获取到的数据最后再是a的值而且a也不应该是一个promise吧。这段代码里有很多的return第一个return是函数整体的返回值给return出去第二个return是reduce函数里传递给下一个的第三个return是为了按顺序将多个异步按顺序串起来。最后一个return是整个函数要返回的值。 之所以现在的打印结果是上面的这个其实可以当成先执行的同步再执行到异步代码。把最后的结果换个写法 async mounted () {const a await this.logInOrder([https://jsonplaceholder.typicode.com/posts/1,https://jsonplaceholder.typicode.com/posts/2,https://jsonplaceholder.typicode.com/posts/3,https://jsonplaceholder.typicode.com/posts/4,https://jsonplaceholder.typicode.com/posts/5])console.log(a, a)}, 或则 mounted () {this.logInOrder([https://jsonplaceholder.typicode.com/posts/1,https://jsonplaceholder.typicode.com/posts/2,https://jsonplaceholder.typicode.com/posts/3,https://jsonplaceholder.typicode.com/posts/4,https://jsonplaceholder.typicode.com/posts/5]).then(a {console.log(a, a)})},打印出来的结果就是我理想中的了。
http://www.hkea.cn/news/14574375/

相关文章:

  • 淘宝网站建设的目的护肤品网页设计图片
  • 商城网站怎么做内链有没有搜索附近手机的软件
  • 做网站有哪些费用手机网站哪些功能
  • 注册了一个域名怎么做网站网站开发亿玛酷1专注
  • 合肥智能建站模板自考网站建设与管理
  • 微信网站建设合同百度官方免费下载
  • 微信可以做网站吗网站建设收费流程
  • 龙岗区网站建设哪个公司好网站建设销售如何接单
  • 大坪网站建设建湖建网站的公司
  • 杭州 高端网站建设 推荐代理浏览器在线
  • 青岛模板自助建站设计网站制
  • 个人网站开发合同火爆网页游戏排行榜
  • 大连哪个公司做网站好chinacd.wordpress变身
  • 网站收录查询入口衡阳电商网站建设
  • 网站开发 activex网络运营和网站运营
  • 微网站模板制作网站建设优化服务价位
  • 河北华宇建设集团有限公司网站重庆网站建设制作设计公司
  • 网页做成软件搜索引擎优化排名案例
  • 响应式网站效果图做多大的wordpress自动发布文章无效
  • 网站外包后百度降权企业宣传册设计
  • 苏州企业网站建设定制金乡县住房和城乡建设局网站
  • 深圳南头高端网站建设为什么浏览器打不开一些网站
  • 网站建站哪个好wordpress首页导航代码
  • 珠海营销型网站建设深圳网站优化提供商
  • 文化馆建设网站WordPress设置域名出错
  • 网站建设的空间是什么手机兼职可以做什么
  • 电子商务的网站的建设内容建筑工程公司黄页
  • 如果网站曾被挂木马四川省和城乡建设厅网站
  • 枣庄手机网站建设报价如果建手机网站
  • 网站建设 中国联盟网一个软件的开发流程图