【问题标题】:display current json object js显示当前json对象js
【发布时间】:2019-02-25 16:01:27
【问题描述】:

我在做电商书店vuejs单页应用网站。

当我选择它时,我需要在 json 中显示特定书籍中的特定(当前)数据(如标题、封面等)。

{
"books": [
    {
        "title": "The Godfather",
        "cover": "",
        "author": "Mario Putzo",
        "ratting": "95%",
        "price": "30",
        "published": "March 10, 1969",
        "description": ""
    },
    {
        "title": "The Sicilian",
        "cover": "",
        "author": "Mario Putzo",
        "ratting": "98%",
        "price": "25",
        "published": "November 1984",
        "description": ""
    },

我试过了:

<div>
    <p>Author: {{currentBook.author}}</p>
    <p>Title: {{currentBook.title}}</p>
    <p>Published {{}}</p>
</div>

var app = new Vue({
    el: "#app",
    data: {
    /// return {
            page: 'home',
            url: "https://api.jsonbin.io/b/5c6d3bf80177dd1751730298",
            books: [],
            currentBook: {},
        }
    }

    bookSelect(string, object) {
        this.page = string;
        this.currentBook = object;
        this.currentBook = this.books.find(obj => obj.title === object.book);
        this.currentBook = this.books.find(obj => obj.author === book);
        this.currentBook = this.books.find(obj => obj.published === book);
        this.currentBook = this.books.find(obj => obj.description === book);
    }
});

【问题讨论】:

  • 从哪里调用bookSelect(...) 方法?你也可以分享api调用和v-bind等代码吗?
  • 您的问题是什么?你可能应该去vuejs.org 学习技巧

标签: json vue.js single-page-application


【解决方案1】:

data 必须是函数而不是对象。把data改成函数:

data() {
    /// return {
            page: 'home',
            url: "https://api.jsonbin.io/b/5c6d3bf80177dd1751730298",
            books: [],
            currentBook: {},
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-18
    • 2021-12-19
    • 2021-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多