vue中fetch请求


1. 请求方式:get

请求参数:menuName

返回的结果:data

created(){

         this._initPageData()

    },

    methods:{

            _initPageData(){

             fetch('http://localhost:3000/category/searchcategory?menuName='+this.menuName, {

              method: 'get'

            }).then(response => response.json()).then(data => {

               this.category = data.data;

               // console.log(this.category)

            })

          }

2. 请求方式:post

请求参数:username,password

返回的结果:data

fetch('http://localhost:3000/users/register', {

         method: 'POST',

         headers: { 'Accept': 'application/json', 'Content-Type': 'application/json'},

         body: JSON.stringify({ username:userPhone, password: userPassword})

         }).then(response => response.json()).then(data => {  

               console.log(data)

               if(data.state){

                alert(dat


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM