<script>new Vue({\tel:'#app',\tdata:{\t\tlists:[],\t\tobj:{type:1,name:2},\t\titems:[]\t},\tmethods:{\t\t//get 第一種方法\t\t\t\tget:function(){\t\t\taxios({\t\t\t\tmethod:'get',\t\t\t\turl:'http://localhost:3333/list'\t\t\t}).then(res=>{\t\t\t\tconsole.log(res);\t\t\t\tthis.lists=res.data.result;\t\t\t}).catch(function(error){\t\t\t\tconsole.log(error)\t\t\t})\t\t}, \t\t//get 第二種方法\t\tget2:function(){\t\t\taxios.get('http://localhost:3333/list')\t\t\t.then(res=>{\t\t\t\tconsole.log(res);\t\t\t\tthis.lists=res.data.result;\t\t\t}).catch(function(error){\t\t\t\tconsole.log(error)\t\t\t})\t\t}, \t\t//get 第三種方法 問號傳參\t\tget3:function(){ \t\t\taxios.get('http://localhost:3333/list',{params:this.obj} //請求的地址是引數的形式 http://localhost:3333/list?type=1&name=2\t\t\t).then(res=>{\t\t\t\tconsole.log(res);\t\t\t\tthis.lists = res.data.result;\t\t\t}).catch(error=>{\t\t\t\tconsole.log(error)\t\t\t})\t\t}, \t\t//send 第一種方法\t\tsend(){\t\t\taxios({\t\t\t\tmethod:'post',\t\t\t\turl:'http://localhost:3333/list_add',\t\t\t\tdata:this.obj\t\t\t}).then((res)=>{\t\t\t\tconsole.log(res);\t\t\t\tthis.items=res.data.result;\t\t\t}).catch(function(error){\t\t\t\tconsole.log(error);\t\t\t})\t\t}, \t\t//send 第二種方法\t\tsend2(){\t\t\taxios.post('http://localhost:3333/list_add',this.obj\t\t\t).then((res)=>{\t\t\t\tconsole.log(res);\t\t\t\tthis.items=res.data.result;\t\t\t}).catch(function(error){\t\t\t\tconsole.log(error);\t\t\t})\t\t},\t\t\t}})\t</script>
最新評論