This repository has been archived by the owner on Jun 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/0.13-dev' into 0.13-dev
- Loading branch information
Showing
33 changed files
with
985 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
--- | ||
title: 事件冒泡 | ||
type: references | ||
order: 1.3 | ||
version: 2.1 | ||
--- | ||
|
||
# 事件冒泡 <span class="api-version">v0.13+</span> | ||
|
||
Weex 2.0 实现了 W3C 标准的事件冒泡机制。 | ||
|
||
### 使用 | ||
|
||
```javascript | ||
<template> | ||
<div class="root" @click="rootClick" bubble="true"> | ||
<text style="font-size: 40px;">{{rootText}}</text> | ||
<div class="outer" @click="parentClick"> | ||
<div> | ||
<text style="font-size: 40px;">{{parentText}}</text> | ||
</div> | ||
<text class="inner" @click="click">{{innerText}}</text> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
module.exports = { | ||
data: { | ||
innerText: 'click me', | ||
parentText: '', | ||
rootText: '' | ||
}, | ||
methods: { | ||
click: function(e) { | ||
this.innerText = 'inner bubble' | ||
}, | ||
parentClick: function(e) { | ||
this.parentText = 'parent bubble' | ||
}, | ||
rootClick: function(e) { | ||
this.rootText = 'root bubble' | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
.inner { | ||
font-size: 40px; | ||
text-align: center; | ||
background-color: #7a9b1b; | ||
padding: 40px; | ||
} | ||
|
||
.outer { | ||
font-size: 40px; | ||
text-align: center; | ||
background-color: #9b7a1b; | ||
padding: 120px; | ||
} | ||
|
||
.root { | ||
font-size: 40px; | ||
text-align: center; | ||
background-color: #7a1b9b; | ||
padding: 80px; | ||
} | ||
</style> | ||
``` | ||
|
||
[try it](http://dotwe.org/vue/fa2957ce3e9eb47ad9ae1da22d845e95) | ||
|
||
运行以上代码,用客户端打开,点击中间的元素,可以看到事件向上传播,依次触发。 | ||
|
||
### 注意 | ||
|
||
需要注意的是: ** 为了兼容之前的版本,Weex 默认不会开启事件冒泡机制。需要在根元素的属性上,添加 `bubble="true"` 来开启冒泡机制。否则,将不会向上传播事件,保持与之前版本的效果相同。 ** | ||
|
||
### stopPropagation | ||
|
||
在事件处理函数中,可以使用 `e.stopPropagation()` 方法,来阻止本次事件向上的传递过程。注意,`e.stopPropagation()` 与 `bubble="true"` 不同,前者只会影响当前元素以及父元素的传播,不会影响子元素的传播;后者是为了版本兼容而增加的开关机制,会全局关闭或者开启冒泡机制,两者可以共同存在使用,如下: | ||
|
||
```javascript | ||
<template> | ||
<div class="root" @click="rootClick" bubble="true"> | ||
<text style="font-size: 40px;">{{rootText}}</text> | ||
<div class="outer" @click="parentClick"> | ||
<div> | ||
<text style="font-size: 40px;">{{parentText}}</text> | ||
</div> | ||
<text class="inner" @click="click">{{innerText}}</text> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
module.exports = { | ||
data: { | ||
innerText: 'click me', | ||
parentText: '', | ||
rootText: '' | ||
}, | ||
methods: { | ||
click: function(e) { | ||
this.innerText = 'inner bubble' | ||
}, | ||
parentClick: function(e) { | ||
this.parentText = 'parent bubble' | ||
e.stopPropagation() | ||
}, | ||
rootClick: function(e) { | ||
this.rootText = 'root bubble' | ||
// e.stopPropagation() | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
.inner { | ||
font-size: 40px; | ||
text-align: center; | ||
background-color: #7a9b1b; | ||
padding: 40px; | ||
} | ||
|
||
.outer { | ||
font-size: 40px; | ||
text-align: center; | ||
background-color: #9b7a1b; | ||
padding: 120px; | ||
} | ||
|
||
.root { | ||
font-size: 40px; | ||
text-align: center; | ||
background-color: #7a1b9b; | ||
padding: 80px; | ||
} | ||
</style> | ||
``` | ||
|
||
[try it](http://dotwe.org/vue/2cc80e19c9b2430fb780234628065a69) | ||
|
||
运行以上代码,用客户端打开,点击中间的元素,可以看到事件向上传播到父元素被终止,不再继续往根元素传播。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
title: 降级方案 | ||
type: references | ||
order: 1.3 | ||
version: 2.1 | ||
--- | ||
|
||
# 降级方案 | ||
|
||
Weex 2.0 降级方案改成模块的形式支持,具体请参考[downgrade](https://www.npmjs.com/package/@weex-project/downgrade) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.