第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

組件的值未更新

組件的值未更新

哈士奇WWW 2021-09-30 13:57:00
我創(chuàng)建了一個 Vue 應(yīng)用程序,其中有一個 HTTP 請求。數(shù)據(jù)返回后,我會更新配置文件值。但是使用此值的所有組件都不會重新加載。下面是更好地解釋我想要完成的代碼。我有主要的 Vue 文件 App.vue:<template>  <div id="app">    <Navigation />    <Header :profile="profile" />    <About :profile="profile" />    <Services :profile="profile" />  </div></template><script>import Navigation from './components/Navigation.vue'import Header from './components/Header.vue'import About from './components/About.vue'import Services from './components/Services.vue'export default {  name: 'app',  components: {    Navigation,    Header,    About,    Services,  },  data() {    return {      profile: { }    }  },  created() {    this.getUserProfile()  },  methods: {    getUserProfile: async function() {      try {        const response = await fetch('http://localhost:7070/v1/home');        const data = await response.json();        this.profile = data;      } catch (error) {        console.error(error);      }    }  }}</script><style></style>如您所見,我在開始時將變量配置文件設(shè)置為空對象。一旦應(yīng)用程序進入掛載狀態(tài),我就可以通過 GET 請求檢索配置文件數(shù)據(jù)。當(dāng)我調(diào)試時,我可以清楚地看到數(shù)據(jù)不是一個空對象。響應(yīng)包含所有數(shù)據(jù)。正如您從應(yīng)用程序文件中看到的,我導(dǎo)入了 4 個文件以向應(yīng)用程序添加 4 個組件。所有組件都以相同的原理完成。這是 navigation.vue 的內(nèi)容:<template>  <nav class="navbar navbar-expand-lg navbar-light fixed-top py-3" id="mainNav">    <div class="container">      <a class="navbar-brand js-scroll-trigger" href="#page-top">Home</a>      <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">        <span class="navbar-toggler-icon"></span>      </button>      <div class="collapse navbar-collapse" id="navbarResponsive">        <ul class="navbar-nav ml-auto my-2 my-lg-0">          <li class="nav-item">            <a class="nav-link js-scroll-trigger" href="#about">About</a>          </li>          <li class="nav-item">            <a class="nav-link js-scroll-trigger" href="#services">Services</a>          </li>
查看完整描述

1 回答

?
森欄

TA貢獻(xiàn)1810條經(jīng)驗 獲得超5個贊

您需要在組件的 JavaScript 部分中訪問profileprop this.profile。


例如,這行不通:


skills: function () {

  if (typeof(profile) == 'undefined') {

    return [];

  }


  return profile.favoriteExpertise.proficient.slice(0, 3);

}

而不僅僅是profile你需要寫this.profile.


將this.放入模板中的能力不會延續(xù)到其他地方。這特別是模板語言的一個特性。在該<script>部分中,您需要this.像在任何其他 JavaScript 代碼中一樣包含 。以這種方式,道具、數(shù)據(jù)、計算屬性和方法都作為 Vue 實例的屬性進行訪問。


查看完整回答
反對 回復(fù) 2021-09-30
  • 1 回答
  • 0 關(guān)注
  • 186 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號