如何使用Nativescript Vue和Axios显示API数据

时间:2018-04-10 11:25:03

标签: vue.js nativescript axios

此代码在Web浏览器中工作,我可以使用v-for检索json数据:

export default {
  data() {
    return {
      orders: []
    }
  },


  created() {
    axios.get('https://development.octavs.com/testapi.json')
    .then(response => {
         this.orders = response.data
    })
    .catch(error => {
      console.log(error);
    })
    }
}

所以我在使用ListView的nativescript vue中尝试这样:

<ListView class="list-group" for="order in orders" @itemTap="onItemTap" style="height:1250px">
          <v-template>
            <FlexboxLayout flexDirection="row" class="list-group-item">
              <Label :text="order.store" class="list-group-item-heading" style="width: 40%" />
             
              <Label :text="order.description" class="list-group-item-heading" style="width: 60%" />
            </FlexboxLayout>
          </v-template>
        </ListView>

但它根本不检索数据也不检索错误消息。

我应该添加什么吗?

我在路由器中使用nativescipt-vue cli模板,所以我已经插入了这些依赖项:

从'axios'导入axios;

从'vue-axios'导入VueAxios;

Vue.use(VueRouter,VueAxios,axios);

1 个答案:

答案 0 :(得分:1)

事实证明我只需要:从'axios'中导入axios;在实际的页面/组件中

<script>
import axios from 'axios';

  export default {
    data () {
      return {
…
…