微前端

https://cangdu.org/micro-app/docs.html#/zh-cn/start

<template>
  <div id="app">
    <div id="nav">
      <router-link to="/">Home</router-link> |
      <router-link to="/about">About</router-link>
      <div>主</div>
      <ul
        v-for="(item, index) in microApps"
        :key="index"
        :class="{ active: item.activeRule == currentPath }"
      >
        <li @click="get(item)">{{ item.name }}</li>
      </ul>
    </div>
    <div id="subapp-viewport">gdgdg</div>
    <router-view />
  </div>
</template>
<script>
import microApps from "./micro-app";
export default {
  data() {
    return {
      currentPath: "/sub-vue/",
      microApps,
    };
  },
  methods: {
    bindCurent() {
      const path = window.location.pathname;
      console.log("path", path);
      if (this.microApps.findIndex((item) => item.activeRule == path) >= 0) {
        this.currentPath = path;
      }
    },
    listenerRouterChange() {
      window.addEventListener("pushState", this.bindCurent);
    },
    get(item) {
      history.pushState(null, item.activeRule, item.activeRule);
      this.currentPath = item.activeRule;
      console.log(item);
    },
  },
  created() {
    this.bindCurent();
    this.listenerRouterChange();
  },
};
</script>
<style lang="scss">
.active {
  color: #42b983;
}

#nav {
  padding: 30px;

  a {
    font-weight: bold;
    color: #2c3e50;

    &.router-link-exact-active {
      color: #42b983;
    }
  }
}
</style>
 

 

posted @ 2022-02-23 09:49  zjxgdq  阅读(11)  评论(0编辑  收藏  举报