How make json data available for my Vue dynamic routes

前端 未结 2 1407
夕颜
夕颜 2021-01-28 05:19

I have a List component where I fetch my date from db/blogs.json:

created() {
    fetch(\'http://localhost:3000/blogs\')
    .then(respo         


        
相关标签:
2条回答
  • 2021-01-28 05:46

    You can send props to the child component in the tag name, in your case:

      //LIST component(PARENT)
      <tamplate>
        <BlogDetail :blogs="blogs"></BlogDetail> //CHILD component
      </template>
    
    0 讨论(0)
  • 2021-01-28 05:50

    Here is the working sandbox.

    Firstly you need to import JSON data from your JSON file correctly. As:

    <script>
    import ListItem from "./ListItem";
    import Blogs from "../../public/db/blogs.json";
    
    export default {
      name: "List",
      components: {
        ListItem
      },
      data() {
        return {
          blogs: Blogs.experiences
        };
      },
      created() {}
    };
    </script>
    

    Have to send props in the router-link as :

    <router-link 
      :to="{ name: 'BlogDetails', params: { id: blog.id,blog:blog }}">More information
    </router-link>
    
    0 讨论(0)
提交回复
热议问题