{"id":526,"date":"2020-02-26T21:18:25","date_gmt":"2020-02-26T13:18:25","guid":{"rendered":"https:\/\/blog.cqdefxxx.com\/?p=526"},"modified":"2020-02-26T21:18:25","modified_gmt":"2020-02-26T13:18:25","slug":"vue-axiosfetch","status":"publish","type":"post","link":"https:\/\/blog.viter.top\/index.php\/2020\/02\/26\/vue-axiosfetch\/","title":{"rendered":"Vue-axios&#038;fetch"},"content":{"rendered":"<h1><strong>fetch<\/strong><\/h1>\n<pre class=\"pure-highlightjs\"><code class=\"\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n&lt;meta charset=\"utf-8\"&gt;\n&lt;meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\"&gt;\n&lt;title&gt;fetch&lt;\/title&gt;\n&lt;meta name=\"description\" content=\"\"&gt;\n&lt;meta name=\"keywords\" content=\"\"&gt;\n&lt;link href=\"\" rel=\"stylesheet\"&gt;\n&lt;script type=\"text\/javascript\" src=\"lib\/vue.js\"&gt;&lt;\/script&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n    &lt;div id=\"box\"&gt;\n    \t&lt;button @click=\"handleClick()\"&gt;\u6b63\u5728\u70ed\u6620&lt;\/button&gt;\n\n        &lt;ul&gt;\n            &lt;li v-for=\"data in datalist\"&gt;\n                &lt;img :src=\"data.poster\"\/&gt;\n                &lt;h3&gt;{{data.name}}&lt;\/h3&gt;\n                &lt;p&gt;{{data.synopsis}}&lt;\/p&gt;\n\n                &lt;ul&gt;\n                    &lt;li v-for=\"item in data.actors\"&gt;\n                        &lt;img :src=\"item.avatarAddress\"\/&gt;\n                        &lt;h4&gt;{{item.name}}&lt;\/h4&gt;\n                    &lt;\/li&gt;\n                &lt;\/ul&gt;\n            &lt;\/li&gt;\n        &lt;\/ul&gt;\n    &lt;\/div&gt;\n    &lt;script type=\"text\/javascript\"&gt;\n    \t\n       new Vue({\n        el:\"#box\",\n        data:{\n            datalist:[]\n        },\n        methods:{\n            handleClick(){\n                fetch(\"json\/test.json\").then(result=&gt;result.json()).then(res=&gt;{\n                    console.log(res);\n                    this.datalist =res.data.films\n                })\n                \/\/post-1\n\n               \/\/ fetch(\"json\/test.json\",{\n               \/\/  method:\"post\",\n               \/\/  headers:{\n               \/\/      \"Content\u2010Type\":\u00a0\"application\/x\u2010www\u2010form\u2010urlencoded\" \n               \/\/  },\n               \/\/  credentials:\u00a0 'include',\n               \/\/  body:\"name=kerwin&amp;age=100\"\n               \/\/ }).then(res=&gt;res.json()).then(res=&gt;{\n               \/\/  console.log(res);\n               \/\/ })\n\n               \/\/post -2 \n                \n                \/\/ fetch(\"json\/test.json\",{\n                \/\/  method:\"post\",\n                \/\/  headers:{\n                \/\/      \"Content\u2010Type\":\u00a0\"application\/json\" \n                \/\/  },\n                \/\/  body:JSON.stringify({\n                \/\/     name:\"kerwin\",\n                \/\/     age:100\n                \/\/  })\n                \/\/ }).then(res=&gt;res.json()).then(res=&gt;{\n                \/\/  console.log(res);\n                \/\/ })\n            }\n        }\n       })\n\n    &lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n<h1>axios<\/h1>\n<pre class=\"pure-highlightjs\"><code class=\"\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n&lt;meta charset=\"utf-8\"&gt;\n&lt;meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\"&gt;\n&lt;title&gt;fetch&lt;\/title&gt;\n&lt;meta name=\"description\" content=\"\"&gt;\n&lt;meta name=\"keywords\" content=\"\"&gt;\n&lt;link href=\"\" rel=\"stylesheet\"&gt;\n&lt;script type=\"text\/javascript\" src=\"lib\/vue.js\"&gt;&lt;\/script&gt;\n&lt;script src=\"https:\/\/unpkg.com\/axios\/dist\/axios.min.js\"&gt;&lt;\/script&gt;\n\n&lt;\/head&gt;\n&lt;body&gt;\n    &lt;div id=\"box\"&gt;\n        &lt;button @click=\"handleClick()\"&gt;\u6b63\u5728\u70ed\u6620&lt;\/button&gt;\n\n        &lt;ul&gt;\n            &lt;li v-for=\"data in datalist\"&gt;\n                &lt;img :src=\"data.poster\"\/&gt;\n                &lt;h3&gt;{{data.name}}&lt;\/h3&gt;\n                &lt;p&gt;{{data.synopsis}}&lt;\/p&gt;\n\n                &lt;ul&gt;\n                    &lt;li v-for=\"item in data.actors\"&gt;\n                        &lt;img :src=\"item.avatarAddress\"\/&gt;\n                        &lt;h4&gt;{{item.name}}&lt;\/h4&gt;\n                    &lt;\/li&gt;\n                &lt;\/ul&gt;\n            &lt;\/li&gt;\n        &lt;\/ul&gt;\n    &lt;\/div&gt;\n    &lt;script type=\"text\/javascript\"&gt;\n        \n       new Vue({\n        el:\"#box\",\n        data:{\n            datalist:[]\n        },\n        methods:{\n            handleClick(){\n              \/\/ axios.get(\"json\/test.json\").then(res=&gt;{\n              \/\/   console.log(res.data);\/\/\u771f\u6b63\u7684\u540e\u7aef\u6570\u636e\u85cf\u5728res.data\n              \/\/   this.datalist= res.data.data.films\n              \/\/ })\n            \n              axios({\n                url:\"https:\/\/m.maizuo.com\/gateway?cityId=110100&amp;pageNum=1&amp;pageSize=10&amp;type=1&amp;k=1384809\",\n                headers:{\n                  'X-Client-Info': '{\"a\":\"3000\",\"ch\":\"1002\",\"v\":\"5.0.4\",\"e\":\"154277371928424093566579\"}',\n                  'X-Host': 'mall.film-ticket.film.list'\n                }\n              }).then(res=&gt;{\n                console.log(res.data);\n                this.datalist= res.data.data.films\n              })\n\n            } \n        }\n       })\n       \/\/vue-resource 2.0 \u4f5c\u8005\u4e0d\u518d\u7ef4\u62a4\uff0c\u6781\u529b\u63a8\u8350 axios\n    &lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>fetch &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta ch &#8230;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[9,10],"_links":{"self":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/posts\/526"}],"collection":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/comments?post=526"}],"version-history":[{"count":0,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/posts\/526\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/media?parent=526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/categories?post=526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/tags?post=526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}