How can I call method in the component from view? (vue.js 2)我的看法是这样的:[cc lang=javascript] England ...
我的看法是这样的:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <ul class="nav nav-tabs nav-cat"> <li role="presentation" class="active">England </li> <li role="presentation">Spain </li> <li role="presentation">Italy </li> </ul> <top-player-view country_id="1"></top-player-view> |
我的组件顶部播放器视图是这样的:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <template> ... </template> export default{ props:['country_id'], created() { this.$store.dispatch('getTopPlayers', this.country_id) } methods: { getPlayer: function(country_id) { this.$store.dispatch('getTopPlayers', country_id) } } } |
我尝试在顶级播放器视图组件中调用 getPlayer 方法。我从视图中调用该方法。你可以在上面看到我的代码
当我单击选项卡时,我检查控制台是否存在错误:
[Vue warn]: Property or method"getPlayer" is not defined on the
instance but referenced during render. Make sure to declare reactive
data properties in the data option. (found in root instance)Uncaught TypeError: getPlayer is not a function
我该如何解决呢?
你需要实际调用元素上的方法。
一种解决方案:
将
本文标题为:关于javascript:如何从视图中调用组件中的方法?
基础教程推荐
- js禁止页面刷新与后退的方法 2024-01-08
- Ajax实现动态加载数据 2023-02-01
- 基于Vue制作组织架构树组件 2024-04-08
- JS前端广告拦截实现原理解析 2024-04-22
- CSS3的几个标签速记(推荐) 2024-04-07
- this[] 指的是什么内容 讨论 2023-11-30
- 关于文字内容过长,导致文本内容超出html 标签宽度的解决方法之自动换行 2023-10-28
- 浅析canvas元素的html尺寸和css尺寸对元素视觉的影响 2024-04-26
- vue离线环境如何安装脚手架vue-cli 2025-01-19
- 浅谈Vue2和Vue3的数据响应 2023-10-08
