【发布时间】: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