关键词搜索

源码搜索 ×
×

前端工作笔记-element ui弹窗嵌套并获取输入

发布2020-03-05浏览7467次

详情内容

主要是在界面上,如果点击个弹窗,再弹窗中,还需要弹出一个框,进行输入查询。目前此笔记就记录了这个!

程序运行截图如下:

点击弹窗:

点击查询,第二层窗口弹出,输入数据:

点击确定并退出,即可:

程序结构如下:

源码如下:

Dialog.vue

  1. <template>
  2. <div>
  3. <el-button type="text" @click="outerVisible = true">点击打开外层 Dialog</el-button>
  4. <el-dialog title="外层 Dialog" :visible.sync="outerVisible">
  5. <OutDialog :openInDialogFunc="openInDialog" :InDlgValue="inputValue"></OutDialog>
  6. <el-dialog
  7. width="50%"
  8. title="内层 Dialog"
  9. :visible.sync="innerVisible"
  10. append-to-body>
  11. <InDialog :closeInDialogFunc="closeInDialog" @inputDlgValue="getInDialogValue"></InDialog>
  12. </el-dialog>
  13. <div slot="footer" class="dialog-footer">
  14. <el-button @click="outerVisible = false">取 消</el-button>
  15. </div>
  16. </el-dialog>
  17. </div>
  18. </template>
  19. <script>
  20. import OutDialog from './OutDialog'
  21. import InDialog from './InDialog'
  22. export default {
  23. components:{
  24. OutDialog,
  25. InDialog
  26. },
  27. methods: {
  28. getInDialogValue(val){
  29. //子传父获取值
  30. this.inputValue = val;
  31. console.log("子传父:" + this.inputValue)
  32. },
  33. openInDialog(){
  34. this.innerVisible = true
  35. },
  36. closeInDialog(){
  37. this.innerVisible = false
  38. }
  39. },
  40. data() {
  41. return {
  42. outerVisible: false,
  43. innerVisible: false,
  44. inputValue : ""
  45. };
  46. }
  47. }
  48. </script>

HelloWorld.vue

  1. <template>
  2. <div class="hello">
  3. <h1>{{ msg }}</h1>
  4. <h2>Essential Links</h2>
  5. <Dialog></Dialog>
  6. </div>
  7. </template>
  8. <script>
  9. import Dialog from './Dialog'
  10. export default {
  11. components:{
  12. Dialog
  13. },
  14. name: 'HelloWorld',
  15. data () {
  16. return {
  17. msg: 'Welcome to Your Vue.js App'
  18. }
  19. }
  20. }
  21. </script>
  22. <!-- Add "scoped" attribute to limit CSS to this component only -->
  23. <style scoped>
  24. h1, h2 {
  25. font-weight: normal;
  26. }
  27. ul {
  28. list-style-type: none;
  29. padding: 0;
  30. }
  31. li {
  32. display: inline-block;
  33. margin: 0 10px;
  34. }
  35. a {
  36. color: #42b983;
  37. }
  38. </style>

InDialog.vue

  1. <template>
  2. <div>
  3. <el-input v-model="input" placeholder="请输入内容"></el-input>
  4. <br/>
  5. <br/>
  6. <el-row>
  7. <el-button type="primary" @click="onSubmit">确定并退出</el-button>
  8. </el-row>
  9. </div>
  10. </template>
  11. <script>
  12. export default {
  13. props:{
  14. closeInDialogFunc: {
  15. type: Function,
  16. default: null
  17. }
  18. },
  19. data() {
  20. return {
  21. input: ''
  22. }
  23. },
  24. methods: {
  25. onSubmit() {
  26. if (this.closeInDialogFunc){
  27. this.$emit("inputDlgValue", this.input)
  28. this.closeInDialogFunc()
  29. }
  30. }
  31. }
  32. }
  33. </script>

OutDialog.vue

  1. <template>
  2. <el-form :inline="true" :model="formInline" class="demo-form-inline">
  3. <el-form-item label="输入数据">
  4. <el-input v-model="formInline.user" placeholder="输入数据"></el-input>
  5. </el-form-item>
  6. <el-form-item label="选择数据">
  7. <el-input v-model="InDlgValue" placeholder="选择数据">
  8. </el-input>
  9. </el-form-item>
  10. <br/>
  11. <el-form-item>
  12. <el-button type="primary" @click="onSubmit">查询</el-button>
  13. </el-form-item>
  14. </el-form>
  15. </template>
  16. <script>
  17. export default {
  18. props: {
  19. openInDialogFunc: {
  20. type: Function,
  21. default: null
  22. },
  23. InDlgValue:{
  24. type: String,
  25. default: null
  26. }
  27. },
  28. data() {
  29. return {
  30. formInline: {
  31. user: '',
  32. region: ''
  33. }
  34. }
  35. },
  36. methods: {
  37. onSubmit() {
  38. if(this.openInDialogFunc)
  39. this.openInDialogFunc()
  40. }
  41. }
  42. }
  43. </script>
  44. <style scoped>
  45. </style>

main.js

  1. // The Vue build version to load with the `import` command
  2. // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
  3. import Vue from 'vue'
  4. import App from './App'
  5. import router from './router'
  6. import ElementUI from 'element-ui';
  7. import 'element-ui/lib/theme-chalk/index.css';
  8. Vue.config.productionTip = false
  9. Vue.use(ElementUI);
  10. /* eslint-disable no-new */
  11. new Vue({
  12. el: '#app',
  13. router,
  14. components: { App },
  15. template: '<App/>'
  16. })

 

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载