[标题中的点击路由会在为dist提供服务后使用prerender-spa插件刷新vuejs中的页面

问题描述 投票:0回答:1

组件之间的连接被破坏。由于我使用的是bootstrap-vue内置路由器链接(使用to =“”而不是href =“”),因此不应该发生哪种情况。该应用程序在无距离运行时运行良好。


App.vue


<template>
  <div class="container">
    <app-header></app-header>
    <div class="row">
      <div class="col-xs-12">
        <transition name="slide" mode="out-in">
          <router-view></router-view>
        </transition>
      </div>
    </div>
  </div>
</template>

<script>
import Header from "./components/Header.vue";
export default {
  components: {
    appHeader: Header
  },
  created() {
    this.$store.dispatch("initStocks");
  }
};
</script>

Header.vue


<template>
  <div>
    <b-navbar toggleable="lg" type="dark" variant="info">
      <b-navbar-brand to="/">Stock Broker</b-navbar-brand>

      <b-navbar-toggle target="nav-collapse"></b-navbar-toggle>

      <b-collapse id="nav-collapse" is-nav>
        <b-navbar-nav>
          <b-nav-item to="/portfolio">Portfolio</b-nav-item>
          <b-nav-item to="/stocks">Stocks</b-nav-item>
          <b-nav-item @click="endDay">End Day</b-nav-item>
          <b-navbar-nav right>
            <b-nav-item right>Funds: {{ funds }}</b-nav-item>
          </b-navbar-nav>
        </b-navbar-nav>
      </b-collapse>
    </b-navbar>
  </div>
</template>

<script>
import { mapActions } from "vuex";

export default {
  data() {
    return {
      isDropdownOpen: false
    };
  },
  computed: {
    funds() {
      return this.$store.getters.funds;
    }
  },
  methods: {
    ...mapActions({
      randomizeStocks: "randomizeStocks",
      fetchData: "loadData"
    }),
    endDay() {
      this.randomizeStocks();
    },
    saveData() {
      const data = {
        funds: this.$store.getters.funds,
        stockPortfolio: this.$store.getters.stockPortfolio,
        stocks: this.$store.getters.stocks
      };
      this.$http.put("data.json", data);
    },
    loadData() {
      this.fetchData();
    }
  }
};
</script>

vue.config.js


module.exports = {
  pluginOptions: {
    prerenderSpa: {
      registry: undefined,
      renderRoutes: ["/", "/portfolio", "/stocks"],
      useRenderEvent: true,
      headless: true,
      onlyProduction: true
    }
  }
};

router / index.js


从'vue'导入Vue从'vue-router'导入VueRouter从“ ../views/Home.vue”导入主页]

Vue.use(VueRouter)

常量路由= [{路径:“ /”,名称:“家”,组件:首页},{路径:“ / stocks”,名称:“股票”,组件:()=> import(/'../views/Stocks.vue')},{路径:“ / portfolio”,名称:“ Portfolio”,组件:()=> import('../ views / Portfolio.vue')}]

常量路由器=新的VueRouter({模式:“历史”,基本:process.env.BASE_URL,路线})

导出默认路由器

vue.js vuejs2 single-page-application prerender
1个回答
0
投票

我在写这篇文章后一分钟就想到了哈哈。

问题是,在App.vue中,我的主div的类别为“容器”,而不是ID为“ app”。

以下更正:


    <template>
      <div id="app"> //correction here
        <app-header></app-header>
        <div class="row">
          <div class="col-xs-12">
            <transition name="slide" mode="out-in">
              <router-view></router-view>
            </transition>
          </div>
        </div>
      </div>
    </template>

© www.soinside.com 2019 - 2024. All rights reserved.