Giter Site home page Giter Site logo

是不是响应拦截器不支持nvue页面啊,今天试了一天,发现在nvue页面拦截器不生效 about luch-request HOT 6 CLOSED

panghuangdehaozi avatar panghuangdehaozi commented on May 26, 2024
是不是响应拦截器不支持nvue页面啊,今天试了一天,发现在nvue页面拦截器不生效

from luch-request.

Comments (6)

lei-mu avatar lei-mu commented on May 26, 2024

没收到类似问题。请求拦截器和响应拦截器是一样的。

from luch-request.

panghuangdehaozi avatar panghuangdehaozi commented on May 26, 2024

请求拦截器也是不生效的,今天我试过发现请求拦截器的token在nvue页面也没有加载到,后来我改用vuex 在vuex中使用,在vuex中发送请求这样是可以的

from luch-request.

lei-mu avatar lei-mu commented on May 26, 2024

是不是用了什么在nvue 里不能用的api

from luch-request.

panghuangdehaozi avatar panghuangdehaozi commented on May 26, 2024

我有开了一个新项目,使用了拦截器,创建nvue页面请求并打印数据
1691142106991
在h5页面数据为(此时拦截器生效)
1691142060236
在App端打印的数据为(此时拦截器并未生效)
1691142082517
当我把页面改为vue页面后,重新运行发现App端拦截器又生效了
所以应该是不支持nvue页面请求的~

from luch-request.

lei-mu avatar lei-mu commented on May 26, 2024

我在模拟器跑了一个demo,页面也是nvue的,是可以应用拦截器的。

import Request from 'luch-request'

const http = new Request({
	baseURL: ''
})


http.setConfig((config) => { /* 设置全局配置 */
  config.baseURL = 'https://www.fastmock.site/mock/26243bdf9062eeae2848fc67603bda2d/luchrequest'
  config.header = {
    ...config.header,
    a: 1, // 演示
    b: 2 // 演示
  }
  config.custom = {
    // auth: false, // 是否传token
    // loading: false // 是否使用loading
  }
  return config
})

http.interceptors.request.use(config => {
	console.log(config);
	config.header.aaaaaaaaaaa =2
	return config
})



http.interceptors.response.use(res => {
	res.data.bbbbbbbbb = 2
	return res
})



export {
	http
}
import {http} from '../service/request.js'


export default {
	updateUser: (data) => http.post('/api/user/update', data)
}
<template>
	<view class="content">
	
		<button @click="getUser">请求</button>
	</view>
</template>

<script>
import api from '@/api/index.js';
export default {
	data() {
		return {
			title: 'Hello'
		};
	},
	onLoad() {},
	methods: {
		getUser() {
			api
				.updateUser({
					id: 2
				})
				.then(res => {
					console.log('局部res', res);
				}).catch(err => {
					console.log('局部err', err);
				});
		}
	}
};
</script>

<style>

</style>

from luch-request.

panghuangdehaozi avatar panghuangdehaozi commented on May 26, 2024

我今天把我的demo重新跑了一遍,发现又没问题了 麻了

from luch-request.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.