【发布时间】:2019-08-29 10:05:10
【问题描述】:
下面的代码从远程服务获取 JSON 数据并将其输入到变量中,该变量稍后也应将其输入到道具中。
之后我操纵道具中的物品。
当然我在尝试改变道具时得到了Vue Error。
代码如下:
<script>
import axios from 'axios'
import { API_BASE_URL } from '../config'
export default {
props: {
items: {
type: Array,
required: false,
default: () => []
}
},
data() {
return {
isLoading: true,
novels: [],
search: "",
isOpen: false,
arrowCounter: 0
}
},
created() {
axios.get(API_BASE_URL + '/novels').then(response => {
this.novels = response.data.data
})
// this.items = this.novels
this.isLoading = false
},
methods: {
getNovel(novel){
this.$router.push({ path: `novel/${novel.id}`})
// this.$router.go(1)
},
onChange(){
// Let's warn the parent that a change was made
this.$emit("input", this.search);
// Let's search our flat array
this.filterResults();
this.isOpen = true
},
filterResults() {
// first uncapitalize all the things
this.novels = this.items.filter(item => {
return item.toLowerCase().indexOf(this.search.toLowerCase()) > -1;
});
}
}
</script>
【问题讨论】:
标签: javascript vue.js prop