Vueのインタラクション
1649 ワード
vue自体はインタラクションをサポートしないため、インタラクション時にモジュールvue-resourceを導入する必要がある.js
1.ファイル内の内容を直接取得する:
2.getはgetを通過する.php'
3.postはpostを通過する.php'
};4.jsonpによるデータ取得
1.ファイル内の内容を直接取得する:
'use strict';
window.onload=function(){
new Vue({
el:'body',
data:{
a:12
},
methods:{
get:function(){
this.$http.get('a.txt').then(function(res){
console.log(res.data);
},function(err){alert(err)});
}
}
});
};
2.getはgetを通過する.php'
'use strict';
window.onload=function(){
new Vue({
el:'body',
data:{
d:12
},
methods:{
get:function(){
this.$http.get('get.php',{'a':1,'b':4}).then(function(res){
console.log(res.data);
},function(err){console.log(err.status)});
}
}
});
};
3.postはpostを通過する.php'
'use strict';
window.onload=function(){
new Vue({
el:'body',
data:{
a:1
},
methods:{
post:function(){
this.$http.post('post.php',{a:1,b:2},{emulateJSON:true}).then(function(res){
alert(res.data)
},function(err){console.log(err.data)});
}
}
});
}
};4.jsonpによるデータ取得
'use strict';
window.onload=function(){
new Vue({
el:'body',
data:{
d:12
},
methods:{
get:function(){
this.$http.jsonp('https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?',{wd:4},{jsonp:'cb'}).then(function(res){
alert(res.data.s);
},function(err){console.log(err.status)});
}
}
});
};