vux 获取后端数据并显示出来并且带 请求头token

news/2024/7/10 1:20:31 标签: vue
methods:{
    printconsole(){
            let that=this;
            //console.log(that.getToken());
            that.$http.post(that.getSvcUrl('/user/getMyUserInfo'),null,{headers: {  null是指请求带的参数
            'Authorization': 'Bearer ' +that.getToken()
            }})
                .then((res2)=>{
                 that.SetUserInfo(res2.data.data);
                console.log(res2.data.data);
                });
            }
        }
}

发送请求并返回数据

注意!
点击事件需要 @click.native="toShow"    如果返回的 数据 是数组 形式:例如 [{"name":"张三","age":"18"}] 那么需要写成 prod[0].name

<template>
    <div id="myAdd">
        <group>
            <calendar title="我的日历" ></calendar>
        </group>
        <group>
            <cell title="cell" value="hello" is-link></cell>
            <cell-box v-for="proddd in prods" :key="proddd"> 
               {{proddd}}
            </cell-box>
            <cell-box>
                cell-box hello world hello world hello world
            </cell-box>
            <cell title="cell" value="hello" is-link></cell>
        </group>
            <div><x-button plain type="primary" @click.native="toShow" style="border-radius:99px;"> 点击</x-button></div>
            <p>{{Goods}}</p>
        <ul>
            <li v-for="prod in prods" :key="prod.id">
               {{prod.prodclassname}}
            </li>
        </ul>    
     </div>
</template>
<script>
import { Group , Calendar,Cell, CellBox ,XButton} from 'vux'
import { setTimeout } from 'timers';
export default {
    name:'myadd',
    components: {
          Group,
          Calendar,Cell, CellBox,XButton
        },
        data (){
            return {
                Goods: '吃吃吃',
                prods:[]
            }
        },
        methods:{
            toShow(){
                let that=this;
                that.$http.post(that.getSvcUrl('/guideProduct/list'))
                    .then((res)=>{
                        setTimeout(()=>{
                             that.prods=(res.data.data.classList)
                             console.log(res.data.data.classList);
                             
                        })
                    })
            }
        }
}
</script>
methods: {
      jumpToIndex () {
        let that = this;
        that.$vux.loading.show({
          text: '请稍后...'
        })
        let par = {
          "logid": that.username,
          "password": that.password,
           
        };
        that.$http.post(that.getSvcUrl('/login/login.do'), par)
          .then((res) => {
            setTimeout(()=>{
              if(res.data.code == 0){
                that.setUser(res.data.data);
                that.$vux.loading.hide() //隐藏加载
                that.$router.push({ path: 'home'})  //这就是路由跳转的写法
              }else{
                that.clearUser()
                that.$vux.loading.hide()
                this.$vux.alert.show({
                  title: '登陆失败',
                  content: res.data.message
                })
              }
            })
          }).catch((err) => {
          console.log(err)
        })
      }



http://www.niftyadmin.cn/n/1868221.html

相关文章

convert(varchar(10),字段名,转换格式) convert 方法的使用

convert(varchar(10),字段名,转换格式) CONVERT(nvarchar(10),count_time,121) 常用 112 &#xff1a;例如&#xff1a;20180612 SELECT product_name,create_time FROM tb_product AS pro WHERE CONVERT(VARCHAR(8),pro.create_time,112)20180829 CONVERT为日期转换函…

HttpURLConnection是什么?

本文使用 HttpURLConnection 发送http请求&#xff08;get、post&#xff09; URLConnection是个抽象类&#xff0c;它有两个直接子类分别是HttpURLConnection和JarURLConnection。另外一个重要的类是URL&#xff0c;通常URL可以通过传给构造器一个String类型的参数来生成一个指…

笛卡尔积 生成 SKU 算法

public class 笛卡尔积生成SKU {private static String[] aa{"a1","a2"};private static String[] bb{"b1"};private static String[] cc{"c1","c2","c3"};private static String[] dd{"d1","d2&q…

ubuntu 安装JDK环境变量配置

export JAVA_HOME/opt/java/jdk1.8.181 export JRE_HOME${JAVA_HOME}/jre export CLASSPATH.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH${JAVA_HOME}/bin:$PATH

RPC例子

首先&#xff0c;定义业务&#xff1a; package com.service;public interface HelloService {String sayHi(String name); }package com.service.impl;import com.service.HelloService;public class HelloServiceImpl implements HelloService{Overridepublic String sayHi(…

枚举工具类

从基础开始&#xff1a; 枚举的定义&#xff1a; public enum SexEnum implements IEnum {Male(1, "男"), Female(2, "女"), Unknown(3, "未知");private int value;private String label;SexEnum(int value, String label) {this.value valu…

JAVA List 排序

import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.List;public class People {String name;Integer age;Date birthDate;// ...省略 get(),set(),constructorpublic static void main(String…