Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新题目 #396

Open
sunshineLixun opened this issue Jul 8, 2022 · 1 comment · May be fixed by #397
Open

新题目 #396

sunshineLixun opened this issue Jul 8, 2022 · 1 comment · May be fixed by #397

Comments

@sunshineLixun
Copy link

基本信息

# 题目难度
difficulty: # medium 

# 题目标题
title: 这个挑战开始,我们将尝试实现一个响应式的数据请求方式

# 题目标签
tags: union, array # separate by comma

题目

这个挑战开始,我们将尝试实现一个响应式的数据请求方式

题目模版

filename: App.vue

<script setup lang="ts">
import { ref, Ref } from 'vue'
  
/**
 * 实现一个请求的Hooks
*/
function useRequest(url: string | Ref<string>) {
	const data = ref(null)
  const error = ref(null)
  const loading = ref(false)
  
  /**
  	你的实现
  */
  
  return {
    data,
    error,
    loading
  }
}
  
// 这里提供了一个基准的url,您可以以这个为基准创建响应式的url
// string url
const baseUrl = 'https://jsonplaceholder.typicode.com/todos/'

// Ref<string> url
/**
  你的实现
*/

const { data, error, loading } = useRequest(baseUrl)
  
</script>

<template>
  <button v-for="i in 5" @click="id = i">{{ i }}</button>
  
  <div v-if="error">{{ error.message }}</div>
  <div v-else-if="data">
    <pre>{{ data }}</pre>
  </div>
  <div v-else-if="loading">Loading...</div>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant