Comments (3)
List item onClick/onSwitchChange 应该是 action 不是 props
抱歉,您是指 onClick/onSwitchChange
等事件不应该放在 props
里面吗?Vue 的 action
具体是指什么?是指 emits
吗?
from taro-ui-vue3.
是的。应该是emits出去。而不是通过props传入。
from taro-ui-vue3.
Vue 3.0 文档确实是建议将自定义事件写在 emits
里面,rfc 里面也列出了为什么这么做的 5 条 Motivation
。
不过,由于 Vue 3.0 的渲染函数 api 采用了扁平式 VNode 结构,事件监听器 (event listeners) 都包含在了 $attrs
里面,以 on
开头的属性 (props
) 会被处理为 v-on
绑定。
{
class: ['foo', 'bar'],
style: { color: 'red' },
id: 'foo',
innerHTML: '',
onClick: foo,
key: 'foo'
}
例如:
<Foo @click="foo" @custom-event="bar" />
无论自定义事件是写在 props
里面,还是 emits
里面,都会被会被编译为:
h(Foo , {
onClick: foo,
onCustomEvent: bar
})
在最终呈现效果和用法上,都是一致的。这一点跟 Vue 2 不同。
在 Vue 2 里,如果把自定义事件写在 props
里面,如: props: { onCustomEvent: Function }
, 则不能使用 v-on
语法 @custom-event="bar"
来触发事件,只能使用 v-bind
语法,即 :onCustomEvent="bar"
来触发。
taro-ui-vue3
现在发布的 alpha 版本是直接采用渲染函数来写的,最大限度地利用了 taro-ui
原有的类型定义文件(便于使用 IDE 对 Typescript 的自动提示)。
现在有一个 feat/sfc 分支,正在使用 SFC 进行重构。其中事件声明部分就都采用 emits
来写了。有兴趣的话,欢迎来 PR。
from taro-ui-vue3.
Related Issues (20)
- 请问下 自定义的文件夹无法在 tsconfig.json设置别名吗? HOT 1
- 使用taro-ui-vue3在钉钉小程序报错 HOT 3
- Taro2.x还是Taro3.x HOT 2
- imagepicker @image-pick=H5图片点击放大效果不生效 HOT 2
- VirtualScroll :itemHeight 单位固定成为了px,无法适配小程序 HOT 3
- '@tarojs/components' does not contain an export named 'View'.
- 如何使用AtTabBar作为自定义tabbar HOT 1
- class多级嵌套下,报错TypeError: insertionPoint.insertAdjacentHTML is not a function HOT 3
- 希望VirtualScroll增加一个列表数据为空的时候显示的结构 HOT 2
- 停止维护通知
- 关于滑动条范围选择组件AtRange小程序模拟器/真机演示不能拖动选择的问题 HOT 3
- 兄弟们 Taroify 也是一个不错的选择
- SwipeAction 第一次触发无反应 HOT 4
- at-search-bar组件的onClear事件无效 HOT 5
- SearchBar怎么一点击搜索那个文字就自动清空了的? HOT 2
- Taro Vue 3.0 报错: SVGElement is not defined HOT 6
- AtSwipeAction 出现相同的id swipeAction-2020 HOT 2
- `AtFloatLayout` 组件滚动穿透问题。 HOT 2
- 全局引入报错 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from taro-ui-vue3.