test.html
1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!doctype html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>测试界面</title>
<!--<script src="https://cdn.jsdelivr.net/npm/babel-polyfill@6.26.0/dist/polyfill.js"></script>-->
<!--<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.js"></script>-->
<!--<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.js"></script>-->
<script src="https://cdn.staticfile.org/vue/2.6.12/vue.min.js"></script>
<script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>
<script>
console.log("ddfdfdff" + Vue);
</script>
</head>
<body>
<div id="app">
请输入关键字:<input type="text" v-model="keyword">
<button @click="sendJsonP(keyword)">查询</button>
<ul>
<li v-for="r in result">{{r}}</li>
</ul>
</div>
<script>
(function() {
var url = 'https://www.baidu.com/sugrec?pre=1&p=3&ie=utf-8&json=1&prod=pc&from=pc_web';
var i = 0;
new Vue({
el: '#app',
data: function() {
return {
keyword: '23',
result: ''
};
},
methods: {
sendJsonP: function(keyword) {
this.$http.jsonp(url, {
params: { wd: keyword },
jsonp: 'cb' // jsonp默认是callback,百度缩写成了cb,所以需要指定下
}).then(function(res) {
this.result = [];
for (i = 0; i < res.data.g.length; i++) {
this.result.push(res.data.g[i].q);
}
});
}
}
});
}());
</script>
</body>
</html>