所以我尝试使用来自pixabay网站的api,但是我没有任何结果,api没有发送任何结果,我使用console.log检查了它,我希望你们能给我一点帮助,谢谢。
这是使用vuejs的代码,所以我试图使用来自pixabay网站的api,但是我没有任何结果,api没有发送任何结果,我使用console.log检查它,我想从你们那里得到一点帮助谢谢你们。
下面是使用vuejs的代码
<template>
<section>
<div class="row">
<form class="form-inline d-flex justify-content-center md-form form-sm mt-0">
<i class="fas fa-search" aria-hidden="true"></i>
<input class="form-control form-control-sm ml-3 w-75" type="text" placeholder="Search"
aria-label="Search" v-model="searchText" v-on:keyup.enter.stop.prevent="search">
</form>
</div>
<!-- Grid row -->
<!-- Grid row -->
<div class="gallery" id="gallery">
<!-- Grid column -->
<div class="mb-3 pics" v-for="image in images" :key="image.id" >
<img class="img-fluid" :src="image.largeImageURL" alt="">
</div>
</div>
</section>
</template>
<script>
// @ is an alias to /src
import HelloWorld from "@/components/HelloWorld.vue";
import axios from 'axios'
export default {
name: "Home",
components: {
HelloWorld,
},
data () {
return {
searchText: '',
amount: 15,
apiUrl: 'https://pixabay.com/api/',
apiKey: '19405941-132a0646104b54c8459f0746c',
images: []
}
},
mounted () {
},
methods:{
search:function(event){
axios
.get( `${this.apiUrl}?key=${this.apiKey}&q=${this.searchText}`)
.then(response => (this.images = response.data.hits))
console.log(this.images)
}
}
};
</script>
>发布于 2020-12-05 23:44:08
按enter键即可提交表单。prevent修饰符位于输入上,但应位于<form>上
<form @submit.prevent>并且可以将其从您的按键事件侦听器中删除:
v-on:keyup.enter="search"https://stackoverflow.com/questions/65158581
复制相似问题