zoukankan      html  css  js  c++  java
  • Vue的异步组件

    方法一、<template>

      <div id="app">
        <button class="btn" @click="clickMe">点我</button>
        <div v-if="show">
       <yibuzujian></yibuzujian>
        </div>
        <router-view />
      </div>
    </template>
    <script>
    export default {
      components:{
        yibuzujian: ()=>import("./yibuzujian")
      },
      data() {
        return {
          show:false,
        };
      },
      methods: {
        clickMe() {
          // this.$toast("你好啊!")
          this.show = !this.show
        }
      },
    };
    </script>
    <style lang="stylus">
    #app {
      display: flex;
      justify-content: center;
      align-items: centerS;
    }
    </style>

    方法二:

    <template>
      <div id="app">
        <button class="btn" @click="clickMe">点我</button>
        <div v-if="show">
          <AsyncList />
        </div>
        <router-view />
      </div>
    </template>
    <script>
    import loading from "./loading";
    import ErroCom from "./ErroCom";
    const AsyncList = ()=>({
      component:import("./yibuzujian"),
      loading: loading, //loading组件
      error:ErroCom,//错误展示
      delay:200,//延迟
      timeout:500,//如果3秒没有加载,就出现error组件
    })
    export default {
      components:{
        AsyncList
      },
      data() {
        return {
          show:false,
        };
      },
      methods: {
        clickMe() {
          // this.$toast("你好啊!")
          this.show = !this.show
        }
      },
    };
    </script>
    <style lang="stylus">
    #app {
      display: flex;
      justify-content: center;
      align-items: centerS;
    }
    </style>
  • 相关阅读:
    类型-String:二进制安全
    影视-纪录片:《魅力柬埔寨》
    植物:探矿植物
    植物-探矿植物:铜草
    扩展名:cs
    扩展名:snk
    Code-Helper:OracleHelper.cs
    Code-Helper:SqlHelper.cs
    Linux: FTP服务原理及vsfptd的安装、配置
    Linux下/etc/fstab文件详解
  • 原文地址:https://www.cnblogs.com/0520euv/p/13893823.html
Copyright © 2011-2022 走看看