简体   繁体   English

<b-list-group-item>在 vue.js CLI 应用程序中未呈现 bootstrap-vue</b-list-group-item>

[英]<b-list-group-item> in vue.js CLI app with bootstrap-vue not rendered

i have a app made with vue-CLI including bootstrap-vue.我有一个使用 vue-CLI 制作的应用程序,包括 bootstrap-vue。 In my App.vue i'am using axios to fetch some sample JSON-data.在我的App.vue中,我使用 axios 来获取一些示例 JSON 数据。 With this simple code with html-tags (UL, LI), data are displayed:使用这个带有 html-tags (UL, LI) 的简单代码,可以显示数据:

 <p v-if="loading">Loading...</p>
    <ul v-else>
      <li v-for="(value, key) in post" :key="key">
        {{ key }} : {{ value }}
      </li>
    </ul>

This is the output:这是 output: 在此处输入图像描述

With code, using bootstrap-tags and the same data, the data is not been displayed in list-items, seems to be a broken rendering.使用代码,使用引导标签和相同的数据,数据没有显示在列表项中,似乎是一个损坏的渲染。

   <b-list-group >
      <b-list-group-item
        href="#"
        class="flex-column align-items-start"
        v-for="result in post"
        v-bind:key="result.userId"
      >
        <div class="d-flex w-100 justify-content-between">
          <h6 class="mb-1">{{ result.title }}</h6>
          <small>{{ result.id }}</small>
        </div>

        <p class="mb-1">{{ result.body }}</p>

      </b-list-group-item>
    </b-list-group> 

This is the output:这是 output: 在此处输入图像描述

The html-code is generated but no data between the tags.生成了 html 代码,但标签之间没有数据。 The element-Inspector (chrome) shows... element-Inspector (chrome) 显示...

在此处输入图像描述

What's the problem?有什么问题? Has anybody an idea?有人有想法吗? Please help.请帮忙。

This is my main.js :这是我的main.js

import Vue from 'vue'
import App from './App.vue'
import VueRouter from 'vue-router'
import JQuery from 'jquery'
let $ = JQuery

import BootstrapVue from 'bootstrap-vue'
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'

Vue.use(BootstrapVue)

Vue.use(VueRouter);

Vue.prototype.$log = console.log;

new Vue({
  el: '#app',
  render: h => h(App)
})

This is my script in Vue.app :这是我在Vue.app中的脚本:

<script>
const productAPI =
  "http://www.m.myapp2go.de/services/getnewsliste.php?typ=news&id=10024";

import axios from "axios";
import Counter from "./Counter";

export default {
  name: "app",
  data() {
    return {
      msg: "Vue.js Template Test App",
      loading: false,
      post: null,
      results: null,
      error: ""
    };
  },
  components: {
    "my-counter": Counter
  },
  created: function() {
    this.loading = true;
    axios
      .get("https://jsonplaceholder.typicode.com/posts/1")
      .then(res => {
        this.loading = false;
        this.post = res.data;
      })
      .catch(err => {
        this.loading = false;
        this.error = err;
      });
  },
  methods: {
    log(message) {
      console.log(message);
    }
  }
};
</script>

That's because the api https://jsonplaceholder.typicode.com/posts/1 returns an object and not an array.这是因为 api https://jsonplaceholder.typicode.com/posts/1返回 object 而不是数组。 If you instead call https://jsonplaceholder.typicode.com/posts you will retrieve an array of objects and your code should work.如果您改为调用https://jsonplaceholder.typicode.com/posts您将检索对象数组并且您的代码应该可以工作。

However, if the API point you're calling is the one you want that means you're iterating the object keys.但是,如果您调用的 API 点是您想要的,则意味着您正在迭代 object 键。 You need to insert the result from the API into an array or remove the v-for and use the post directly.您需要将 API 的结果插入数组或删除v-for并直接使用post

axios
  .get("https://jsonplaceholder.typicode.com/posts/1")
  .then(res => {
    this.loading = false;
    this.post = [res.data];
  })
  .catch(err => {
    this.loading = false;
    this.error = err;
  });

or或者

<b-list-group >
  <b-list-group-item
     href="#"
     class="flex-column align-items-start"
   >
     <div class="d-flex w-100 justify-content-between">
       <h6 class="mb-1">{{ post.title }}</h6>
       <small>{{ post.id }}</small>
     </div>
   <p class="mb-1">{{ post.body }}</p>
 </b-list-group-item>
</b-list-group> 

new Problem with JSON posted in an other task JSON 的新问题发布在其他任务中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM