javascript - 如何传递 @click(data) 道具来填写在 Vue 中有另一个组件的表单
问题描述
//this parent component
<a href="#" @click="albumEdit(album)"></a>
<publishalbum-component :click-btn="albumEdit(album)"> </publishalbum-component>//child component send click funct6ion vai props
//in child component execute this method
albumEdit(album) {
this.editMode = true;
this.form.reset();
this.form.clear();
this.form.fill(album);
}
,
但不起作用......如何做到这一点我是 vuejs 的新手,所以任何人都可以帮我做那个功能
解决方案
一种方法是使用事件:
//this parent component
<a href="#" @click="albumEdit(album)"></a>
...
<publishalbum-component @clickedButton="albumEdit(album)"> </publishalbum-component>
...
methods: {
albumEdit(album) {
this.editMode = true;
this.form.reset();
this.form.clear();
this.form.fill(album);
}
}
//in child component emit an event and a parent component shuld receive it and call the albumEdit function
this.$emit('clickedButton')
另一种方法:
//this parent component
<a href="#" @click="albumEdit(album)"></a>
...
...
<publishalbum-component :clickedButton="albumEditCallback"> </publishalbum-component>
methods: {
albumEditCallback() {
this.albumEdit(this.album) // depends on where you store an album object
},
albumEdit(album) {
this.editMode = true;
this.form.reset();
this.form.clear();
this.form.fill(album);
}
}
//in child component execute this method
this.clickedButton()
推荐阅读
- sql - 尽管覆盖了所有表上的索引,如何加快速度很慢的 4 路 SQLITE 内连接
- jquery - MVC 问题在按钮单击时从 JSon 对象填充 JQuery DataTable
- python - 捕获键盘事件
- sql - 在Postgresql中获取满足x条件的行的行号
- javascript - Instagram - 如何以编程方式滚动以加载关注者/关注者
- python - RuntimeError:给定组 = 1,大小为 [32、3、3、3] 的权重,预期输入 [1、4、160、40] 有 3 个通道,但有 4 个通道
- c - C 编程:错误:赋值给数组类型的表达式
- spatial-query - 为什么这个空间查询返回空?
- stacked-chart - 重新绘制带有重叠单元格的堆叠条形图
- apache-spark - 如何将参数传递给 spark.sql(""" """)?