小编And*_*sen的帖子

获取数据之前的 Vue 渲染组件

当我使用数据属性渲染组件时,它会在获取数据之前加载 html。这导致没有数据被显示。直到我使用渲染函数的标签在组件内进行 api 调用。

谁能告诉我在获取数据后如何渲染我的组件。我已经尝试过 v-if 条件。它呈现我的页面没有数据。如果我删除 v-if 它说无法读取未定义的属性。

  <div class="score">
          <p class="number">{{company.storeScore}} test</p>
          <p class="text">Tilfredhedscore</p>
  </div>

getStoreScore (condition) {
      return axios.post('API-LINK', {
        storeId: '5b7515ed5d53fa0020557447',
        condition: condition
      }).then(response => {
        this.company.storeScore = response.data.result
        this.company.amount = {
          'total': response.data.amount.total,
          'zero': {
            'amount': response.data.amount.zero,
            'percentage': (response.data.amount.zero !== 0 ? response.data.amount.zero / response.data.amount.total * 100 : 0)
          },
          'one': {
            'amount': response.data.amount.one,
            'percentage': (response.data.amount.one !== 0 ? response.data.amount.one / response.data.amount.total * 100 : 0)
          },
          'two': {
            'amount': response.data.amount.two,
            'percentage': (response.data.amount.two !== 0 …
Run Code Online (Sandbox Code Playgroud)

javascript api vue.js vue-component

2
推荐指数
1
解决办法
9256
查看次数

标签 统计

api ×1

javascript ×1

vue-component ×1

vue.js ×1