微信小程序开发随手记

微信小程序开发 day06、day07 - event.cu

2022-02-28  本文已影响0人  望穿秋水小作坊

一、day06 event.currentTarget、data-*、自定义数据属性、组件间通信

1、浏览器事件中 event 的 target、 currentTarget 有什么不同?

2、执行代码 console.log(event) ,为什么从chrome控制台我们看到currentTarget的属性是null?然而代码中 console.log(event.currentTarget) 就能拿到正确的值呢?

 > PointerEvent {isTrusted: true, pointerId: 1, width: 1, height: 1, pressure: 0, …}
v PointerEvent {isTrusted: true, pointerId: 1, width: 1, height: 1, pressure: 0, …}
isTrusted: true
altKey: false
currentTarget: null

Note: The value of event.currentTarget is only available while the event is being handled. If you console.log() the event object, storing it in a variable, and then look for the currentTarget key in the console, its value will be null.
Instead, you should either use console.log(event.currentTarget) to be able to view it in the console or use the debugger statement, which will pause the execution of your code thus showing you the value of event.currentTarget.

3、通过执行下面代码,分别在setTimeout之前和之后观察【chrome控制台日志】,加深理解。

var foo = {};
for (var i = 0; i < 100; i++) {
  foo["longprefix" + i] = i;
}
console.log(foo);
setTimeout(() => {
  console.log("====");
  foo.longprefix1 = "abc";
}, 5000);

4、<button data-teacher-name="lsp">btn</button> 中的 data-* 是什么语法?如何在JavaScript代码中获取?

5、小程序组件内部如何触发外部 <component-tag-name bind:myevent="onMyEvent" /> 的事件?

Component({
  properties: {},
  methods: {
    onTap: function(){
      var myEventDetail = {} // detail对象,提供给事件监听函数
      var myEventOption = {} // 触发事件的选项
      this.triggerEvent('myevent', myEventDetail, myEventOption)
    }
  }
})

一、day07 防抖、搜索页设计

1、如下搜索页面做增加防抖操作,主要目的是什么?

image.png

2、小程序里面有官方富文本组件吗?

3、如下页面,要实现搜索条固定,搜索结果滚动的布局,怎么设计?

image.png
// page页面
page {
  padding-top: 56px;
}

// 搜索框
.search {
  position: fixed;
  top: 0;
  left: 20rpx;
  right: 20rpx;
}
上一篇 下一篇

猜你喜欢

热点阅读