• vue 插槽 - 具名插槽


    vue 插槽 - 具名插槽

    在这里插入图片描述
    在这里插入图片描述
    **创建 工程:
    H:\java_work\java_springboot\vue_study

    ctrl按住不放 右键 悬着 powershell

    H:\java_work\java_springboot\js_study\Vue2_3入门到实战-配套资料\01-随堂代码素材\day05\准备代码\09-插槽-具名插槽

    vue --version
    vue create v-name-slot-demo
    cd v-name-slot-demo
    npm run serve

    App.vue

    <template>
      <div>
        <MyDialog>
          <!-- 需要通过template标签包裹需要分发的结构,包成一个整体 -->
          <template v-slot:head>
            <div>我是大标题</div>
          </template>
    
          <template v-slot:content>
            <div>我是内容</div>
          </template>
    
          <template #footer>
            <button>取消</button>
            <button>确认</button>
          </template>
        </MyDialog>
      </div>
    </template>
    
    <script>
    import MyDialog from "./components/MyDialog.vue";
    export default {
      data() {
        return {};
      },
      components: {
        MyDialog,
      },
    };
    </script>
    
    <style>
    body {
      background-color: #b3b3b3;
    }
    </style>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37

    MyDialog.vue

    <template>
      <div class="dialog">
        <div class="dialog-header">
          <!-- 一旦插槽起了名字,就是具名插槽,只支持定向分发 -->
          <slot name="head"></slot>
        </div>
    
        <div class="dialog-content">
          <slot name="content"></slot>
        </div>
        <div class="dialog-footer">
          <slot name="footer"></slot>
        </div>
      </div>
    </template>
    
    <script>
    export default {
      data() {
        return {};
      },
    };
    </script>
    
    <style scoped>
    * {
      margin: 0;
      padding: 0;
    }
    .dialog {
      width: 470px;
      height: 230px;
      padding: 0 25px;
      background-color: #ffffff;
      margin: 40px auto;
      border-radius: 5px;
    }
    .dialog-header {
      height: 70px;
      line-height: 70px;
      font-size: 20px;
      border-bottom: 1px solid #ccc;
      position: relative;
    }
    .dialog-header .close {
      position: absolute;
      right: 0px;
      top: 0px;
      cursor: pointer;
    }
    .dialog-content {
      height: 80px;
      font-size: 18px;
      padding: 15px 0;
    }
    .dialog-footer {
      display: flex;
      justify-content: flex-end;
    }
    .dialog-footer button {
      width: 65px;
      height: 35px;
      background-color: #ffffff;
      border: 1px solid #e1e3e9;
      cursor: pointer;
      outline: none;
      margin-left: 10px;
      border-radius: 3px;
    }
    .dialog-footer button:last-child {
      background-color: #007acc;
      color: #fff;
    }
    </style>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
  • 相关阅读:
    设计模式 结构型模式 - 享元模式(七)
    OPENCV实现暴力特征匹配
    vector实现——memcpy拷贝问题
    Kernel: config: NET_FLOW_LIMIT;netdev_max_backlog
    续:将基于Nasm汇编的打字小游戏,移植到DOSBox
    .360勒索病毒解密方法|勒索病毒解决|勒索病毒恢复|数据库修复
    拯救pandas计划(25)——向量化运算优化循环代码
    pytorch的GPU版本(torch.cuda.is_available()返回False)
    电子科技大学《数据库原理及应用》(持续更新)
    springboot+elk日志
  • 原文地址:https://blog.csdn.net/wowocpp/article/details/133931582