单独调用接口时使用（单文件），如果是vue框架不要使用


不会有跨域问题的调用
`第一种`

第一步token获取接口

```js
let qs = Qs
const res1 = await axios({
      url: "https://security.xmem.tech/auth/realms/xcloud/protocol/openid-connect/token",
      method: "post",
      data: qs.stringify({
            client_id: "xcloud",
            username: "xhscreen",
            password: "Xh.!@#$2021",
            grant_type: "password",
          })
      })
      this.token = "Bearer " + res1.data.access_token`
```

第二步

apiUrl = 'http://192.168.1.242:8081'

    let res = await axios({
       url: `${apiUrl}/open/api/mjg/project/list`,
    	method: 'get',
    	params: {type: '11'},
    	headers: {
    		Authorization: this.token,
    		'Content-Type': 'application/json;charset=utf-8'
        }
     }) 

 `第二种使用原生api调用`

     fetch(`${apiUrl}/open/api/mjg/project/list`, {
       method: "GET", 
       headers: {
       		Authorization: this.token,
       		'Content-Type': 'application/json;charset=utf-8'
    	},
    }) .then((response) => { })

 有封装的一个promise方法 （以基本情况为基准使用） // 原生接口封装


          fetchFn(url, params = { headers: {}, data: {} }, method = 'GET',) {
                    const newMethod = method.toLocaleUpperCase()
                    
                    var urlencoded = new URLSearchParams();
                    Object.keys(params?.data).forEach(item => {
                        urlencoded.append(item, params?.data[item])
                    })
    
                    const header = {
                        Authorization: this.token,
                        'Content-Type': 'application/json;charset=utf-8'
                    }
                    const dataGet = {
                        method: newMethod, // *GET, POST, PUT, DELETE, etc.
                        headers: Object.assign({}, header, params?.headers)
                    }
                    const datNoaGet = {
                        method: newMethod, // *GET, POST, PUT, DELETE, etc.
                        headers: Object.assign({}, header, params?.headers),
                        body: urlencoded, // body data type must match "Content-Type" header
                    }
    
                    return new Promise((resolve, reject) => {
                        fetch(url, newMethod == "GET" ? dataGet : datNoaGet).then(res => resolve(res.json()))
                    })
    
                },
    
    
    接口调用
     let res = await fetchFn('${apiUrl}/open/api/mjg/project/list')
      console.log(res, "res");



