VueJs: 在子组件中修改选择值后触
P粉878542459
P粉878542459 2023-09-04 17:10:56
[Vue.js讨论组]
<p>我正在使用VueJs,我的父组件中有这个子组件,当子组件的选择变化时,我需要在父组件中触发一个函数。</p> <p><strong>子组件:</strong></p> <pre class="brush:php;toolbar:false;">watch: { selectCoin() { this.$emit(&quot;currencyType&quot;, this.selectCoin[&quot;title&quot;]); } }</pre> <p>我在<strong>父组件</strong>中使用的子组件:</p> <pre class="brush:php;toolbar:false;">&lt;app-select-coin @coin=&quot;body.value = $event&quot; @currencyType=&quot;body.currencyType = $event&quot; :data=&quot;body&quot; /&gt;</pre> <p>当子组件响应父组件的$emit时,我需要调用这个方法:</p> <pre class="brush:php;toolbar:false;">methods :{ myFunction() { } }</pre>
P粉878542459
P粉878542459

全部回复(1)
P粉312631645

我通过在 @currencyType 的 "v-on" 中添加函数,并将从子组件中接收到的值作为参数传递给它,成功完成了这个任务。

<app-select-coin
  @coin="body.value = $event"
  @currencyType="myFunction(body.currencyType = $event)"
  :data="body"
/>
methods :{
   myFunction(ct) {

   }
}
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号