zoukankan      html  css  js  c++  java
  • teleport 传送门

    传送 组件 或者内容 到特定的区域 

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>lesson 30</title>
      <style>
        .area {
          position: absolute;
          left: 50%;
          top: 50%;
          transform: translate(-50%, -50%);
           200px;
          height: 300px;
          background: green;
        }
        .mask {
          position: absolute;
          left: 0;
          right: 0;
          top: 0;
          bottom: 0;
          background: #000;
          opacity: 0.5;
          color: #fff;
          font-size: 100px;
        }
      </style>
      <script src="https://unpkg.com/vue@next"></script>
    </head>
    <body>
      <div id="root"></div>
      <div id="hello"></div>
    </body>
    <script>
      // teleport 传送门
      const app = Vue.createApp({
        data() {
          return {
            show: false,
            message: 'hello'
          }
        },
        methods: {
          handleBtnClick() {
            this.show = !this.show;
          }
        },
        template: `
          <div class="area">
            <button @click="handleBtnClick">按钮</button>
            <teleport to="#hello">
              <div class="mask" v-show="show">{{message}}</div>
            </teleport>
          </div>
        `
      });
    
      const vm = app.mount('#root');
    </script>
    </html>

     

    可以把组件的某些 dom  元素传递到特定位置 

    越努力越幸运
  • 相关阅读:
    常用css3属性
    jQuery瀑布流
    jQuery事件对象
    jQuery动画
    面向对象复习
    php 面向对象
    git
    存储数据
    ajax
    对象
  • 原文地址:https://www.cnblogs.com/guangzhou11/p/14339623.html
Copyright © 2011-2022 走看看