javascript - 如何在按钮单击 vue.js 上导入其他组件
问题描述
我想在单击按钮时显示其他组件,当然我也想发送参数,我该怎么做?
我只知道 vue 中的基本用法导入,这里是我创建的。
这是我的模板父母
<template>
<div class="detail-project">
<selectpersons></selectpersons>
</div>
<button v-on:click="selectPerson(param1, param2)"></button>
</template>
这是我的脚本
import selectpersons from './ActionDetailProject/selectPerson.vue';
export default {
components: {
selectpersons
},
methods: {
selectPerson(param1, param2){
//not sure what i have to write here...
},
}
使用此代码,无需单击按钮即可显示组件,我想在selectpersons
单击按钮时显示组件
解决方案
您希望组件selectpersons在有人单击按钮之前不可见吗?然后做这样的事情:
<template>
<div class="detail-project">
<selectpersons v-show="visible"></selectpersons>
</div>
<button v-on:click="selectPerson(param1, param2)"></button>
</template>
export default {
data: {
visible: false,
},
components: {
selectpersons
},
methods: {
selectPerson(param1, param2){
this.visible = true
},
}
推荐阅读
- css - 显示混淆了 div 的大小
- eclipse - 项目元素中的这个 Eclipse 4.9.0 图标是什么意思?
- javascript - 用于在滚动时将导航栏文本更改为图像的 Java 脚本
- python - 线性回归 - 预测 ŷ
- purescript - 为来自 Halogen 的查询/请求获取“为表达式推断出无限类型”
- python-3.x - 如何在windows上运行QT平台插件
- linux - 为 Python 命名 make altinstall
- npm - “Cypress Run”的路径问题
- elasticsearch - 在 Elasticsearch 中的长文本中搜索带有空格的字符串
- php - 如果 PHP 中存在数组,则跳过添加到数组