Comments (6)
直接 @click="foo(item)"
即可
是可以提一下
from v2.cn.vuejs.org.
所以只能写成文档中的“Inline Statement Handler”咯?这样感觉 method handler 在列表里就有点鸡肋了,是否可以在 method handler 里通过 this.item
得到呢?感觉这样蛮方便的,也就不需要 inline statement handler 了
(我理解的对吗?)
from v2.cn.vuejs.org.
这样的话 method 的 this
context 就是不确定的了... 会让代码很难理解的。inline statement handler 没什么问题啊
from v2.cn.vuejs.org.
这会导致相同的逻辑在普通场景可以直接 method handler,然后通过 this
拿到相应的数据,而在列表中则不行,必须通过 inline 的方式,而且除了 item
其它的其实都可以通过 this
拿到,不需要在 template 里显示写明,总觉得不方便就是了……
而且在 v-for
里 item
和 items
之外的 key 应该都是可以被直接识别的,现在 template 里的 context 和 method handler 里的 this context 差一点点,对应不起来,从这个角度把两边对应一下我觉得反而好理解一些,实现角度应该就是先 Object.create
然后 proxy
吧?印象中你以前版本好像这么实现过我还觉得蛮好的……
from v2.cn.vuejs.org.
methods 的 API 设计遵循的是一个简单的道理:任何 method 内部的 this
永远指向其所属的 vm 实例。如果一个 method 的 this
会因为其在模板中被调用的位置而改动,那么 vm.method()
该如何理解呢?
在模板里的情况更类似于:
vm.items.forEach(function (item) {
vm.method(item)
})
method
并不存在于 for 的 scope 上,而是存在于 vm 上。
另外,现在 1.0 阶段必须考虑 API 的稳定性,不可能随便就上 breaking change 的。
from v2.cn.vuejs.org.
got
from v2.cn.vuejs.org.
Related Issues (20)
- Vue 3 Docs are ready for translation! HOT 2
- components.md-动态组件-示例代码:频繁切换home/posts/archive会使页面scroll down HOT 1
- "export 'default' (imported as 'Vue') was not found in 'vue'
- 小疑惑 HOT 4
- Vue 不能检测以下数组的变动:通过索引或长度改变数组。有歧义
- 关于中文站跳转的建议(仅针对中文站) HOT 2
- select option v-for 出错 HOT 1
- component 标签动态事件
- 教程 -> 组件基础 -> 监听子组件事件 -> 在组件上使用 v-model 菜单对应的地址被重定向到了错误的页面
- “v2.x中文文档->深入了解组件->动态组件 & 异步组件” 中存在病句
- vue2的选项框,多选不起作用 HOT 1
- amazing url, refresh forever HOT 3
- v-if与v-for一起使用时的介绍错误 HOT 1
- 侦听器这节文档的最后的测试demo无法正常运行 HOT 2
- website error for cn.vuejs.org HOT 5
- API list not found for cn.vuejs.org/v2/api/ HOT 1
- 标题:在 v-for 里使用范围,是否翻译不当?
- https://v2.cn.vuejs.org/ 搜索功能失效,跳转地址错误 HOT 3
- Vue.config.productionTip = false 无效 HOT 2
- Inaccuracy in comparisons guide
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 v2.cn.vuejs.org.