1-2交互 vue-resouce

    xiaoxiao2021-03-26  18

    vue交互方式

    get

    get交互如下所示:两个方法,一个成功,一个失败。

    methods:{ get: function () { this.$http.get('1-1.html').then(function (res) { res是一个对象,里面包含状态码,包含数据 console.log(res.data); }, function () { console.log(2) }) } } 与服务器做交互:

    methods:{ get: function () { this.$http.get('a.php',{ a:1,b:2 //后面是发送给服务器的参数 }).then(function (res) { console.log(res.data); }, function () { console.log(2) }) } }

    post

    methods:{ get: function () { this.$http.post('a.php',{ a:1,b:2 },{ emulateJSON:true //post提交需要写一个这样的声明 }).then(function (res) { console.log(res.data); }, function () { console.log(2) }) } }

    jsonp

    接口

    https://sug.so.360.cn/suggest?callback=suggest_so&word=a <input type="button" value="按钮" @click="get()"> methods:{ get: function () { this.$http.jsonp('https://sug.so.360.cn/suggest',{ word:'a' },{ }).then(function (res) { console.log(res.data.s); }, function (res) { console.log(res.status); }); } }

    转载请注明原文地址: https://ju.6miu.com/read-658668.html

    最新回复(0)