【发布时间】:2021-04-07 22:17:45
【问题描述】:
我是 Vue.js 的初学者,想做一个使用 API 的项目。这个项目最初是由 TraversyMedia 使用 React 完成的,但它看起来非常简单,可以转换为 Vuejs。我的问题是我不确定如何在 API 中搜索特定演员。搜索栏检测到输入,但我在查询 API 时遇到问题。*
<template lang="">
<div>
<!-- Breaking Bad -->
<Header></Header>
<Search v-on:wordChange="onWordChange"></Search>
<ActorList v-bind:characters="actorInfo"></ActorList>
<!-- characters is the name of the property we want to show up in the child component -->
<!-- {{ actorInfo.length }} -->
<Actor></Actor>
</div>
</template>
<script>
import Header from "./components/Header";
import Search from "./components/Search";
import ActorList from "./components/ActorList";
import Actor from "./components/Actor";
import axios from "axios";
export default {
name: "App",
data: function() {
return { actorInfo: [] };
},
components: {
Header,
Search,
ActorList,
Actor
},
mounted() {
axios
.get("https://www.breakingbadapi.com/api/characters?name", {})
.then((response) => {
this.actorInfo = response.data;
// this.datas = response.data;
// console.log(response.data);
})
.catch(function(error) {
console.log(error);
});
//This is how to get all data from the api endpoint with axios
},
methods: {
onWordChange: function(searchTerm) {
console.log(searchTerm);
}
}
};
</script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: "Montserrat";
font-size: 15px;
color: white;
background: rgb(0, 0, 0);
background: linear-gradient(
90deg,
rgba(0, 0, 0, 1) 0%,
rgba(2, 44, 23, 1) 33%,
rgba(2, 44, 23, 1) 66%,
rgba(0, 0, 0, 1) 100%
);
}
</style>
【问题讨论】:
-
mounted不返回任何内容。mounted从未使用过。 -
我明白了,应该改用什么?我应该改用 Method 吗?
-
不是我想要的。记住,我可以显示 API 的内容。我有图像和数据显示。我只是不确定如何搜索特定演员并显示该信息
标签: javascript vue.js search axios