💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
### 说明: ~~~ 官方已停止对VueResource进行更新 推荐使用axios 但axios不支持jsonp ~~~ ~~~ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <script src="https://cdn.jsdelivr.net/npm/vue-resource@1.5.1"></script> </head> <body> <div id="test"> <input type="text" @keyup.enter="submit"> <!-- @keyup.enter="submit" 当键盘enter按键时触发一个事件submit --> <!-- 动态的添加数据 --> <p>{{title}}</p> <img v-bind:src="url" alt=""> <p></p> </div> <script> new Vue({ //作用位置 el:"" el:"#test", //数据 data:{ title:"三体", url:"https://img1.doubanio.com/view/subject/m/public/s2768378.jpg" }, //方法 methods: { submit(event) { //成功的情况下执行的函数 var self = this; let value = event.target.value;//获取输入框中的数据 let url = `https://api.douban.com/v2/movie/search?q=${value}&count=1` console.log(value); this.$http.jsonp(url).then(res=>{ this.handleData(res.body); }) }, handleData(res){ console.log(res) let title=res.subjects[0].title; let url=res.subjects[0].images.small; this.title=title; this.url=url; } } }) </script> </body> </html> ~~~