typescript - 如何从 Vuetify 对话框访问数据?
问题描述
我正在使用 VueJS Vuetify 框架,我需要从对话框中获取数据?如何从 app.vue 访问对话框 NewUserPopup.vue 的数据,例如用户名或密码?
- App.vue = 主模板
- NewUserPopup.vue = 对话框模板,在 app.vue 中导入
对话框 NewUserPopup.vue:
<template>
<v-dialog v-model="dialog" max-width="600px">
<template v-slot:activator="{ on }">
<v-btn v-on="on" color="primary" class="mb-3">Add new user</v-btn>
</template>
<v-card>
<v-card-title>
<h3 class="primary--text">Add a New User</h3>
</v-card-title>
<v-card-text>
<v-form class="px-3">
<v-text-field label="Username" v-model="username" prepend-icon="account_box"></v-text-field>
<v-text-field label="Firstname" v-model="firstname" prepend-icon="person"></v-text-field>
<v-text-field label="Lastname" v-model="lastname" prepend-icon="person"></v-text-field>
<v-text-field :type="'password'" label="Password" v-model="password" prepend-icon="edit"></v-text-field>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn class="primary mx-0 mt-3" @click="submit" >
Add User
<v-icon right>done</v-icon>
</v-btn>
</v-card-actions>
</v-form>
</v-card-text>
</v-card>
</v-dialog>
</template>
<script lang="ts">
export default {
data () {
return{
dialog: false,
username: '',
firstname: '',
lastname: '',
password: '',
}
},
methods:{
submit(){
this.dialog = false;
}
}
}
</script>
主 App.vue:
<template>
<v-app >
<new-user-popup></new-user-popup>
</v-app>
</template>
<script lang="ts">
import Vue from 'vue';
import NewUserPopup from './components/NewUserPopup.vue'
export default {
name: 'App',
components:{
NewUserPopup
},
data () {
return{
}
},
};
</script>
如何访问数据?
解决方案
你有两个解决方案:
您可以使用密码和用户名创建一个商店,也可以在 App.js 中声明用户名和密码,将它们传递给您的对话框并发出更改。
推荐阅读
- javascript - 将所有变量保存为本地 cookie(html 和 javascript)
- spring-data-jpa - JPA:使用 @Column(columnDefinition = "boolean default true") 不会在 H2 数据库中将布尔值设置为 TRUE
- wso2 - 我可以更改列出的服务提供商的数量吗?
- excel - 使用 VBA 从 URL 获取数据
- ios - 如何从 SwiftUI 视图使用后退按钮推送到 UIKit ViewController
- python-3.x - PySide2 / QLayout:无法向 QHBoxLayout 添加空布局
- excel - 将 Excel 拆分为单独的文件夹,然后在每个文件夹中都有文件。文件夹和文件都与工作表命名相同
- java - 将小于 controlValue 的任何元素的值加倍。例如:如果 controlValue = 10,则 dataPoints = {2, 12, 9, 20} 变为 {4, 12, 18, 20}
- php - 如何在 FPDF 中使用 Open-type SVG 字体文件的默认字体颜色?
- java - 网络答案的单元测试