Vue前端页面向后台传参的三种方式

1.json格式

      const params = {
    
    
        "name": "张三",
        "password": "123456",     
      }
      try {
    
    
        getData(params).then(resp => {
    
    
          const {
    
     data } = resp.data
          console.log(data)
        })
      } catch (e) {
    
    
        console.log(e)
      }

2.formdata形式

      const name = '张三'
      const password= '123456'
      let formdata = new FormData()
      formdata.append('name', name )
      formdata.append('password', password )
       try {
    
    
        getData(formdata).then(resp => {
    
        // 调用接口方法
          const {
    
     data } = resp.data
          console.log(data)
        })
      } catch (e) {
    
    
        console.log(e)
      }
      

3.form表单形式

只能提交字符串形式,不能提交数组,若数据为数组,需要将数组拼接为字符串

<form method="post" enctype="application/msexcel"
                              action="/drugrelctrl-web/getData">  //传参地址
   <input type="text"  name="password"  :value="password" />   // 输入文本
   <input type="submit"  class="submitBtn"   value="提交" />  //提交按钮
</form>
         
<script>
export default{
    
    
	data(){
    
    
	  return{
    
    
		password:"123456"
	}
  }
}	
</script>

猜你喜欢

转载自blog.csdn.net/weixin_42164004/article/details/108650606