一般哪里常用ref用来绑定数据

来源:5-3 Vue3数据绑定显示列表数据

qq_蓝骏毅_04076633

2021-05-09

export default defineComponent({
  name: 'Home',
  setup() {
    console.log("setup");

    const  ebooks = ref();

    const ebooks1 = reactive({books: []});

    onMounted(() => {
      console.log("onMounted");
      axios.get("http://localhost:8880/ebook/list?name=Spring").then( (response) => {

        const data = response.data;
        //content对应电子书列表
        ebooks.value = data.content;

        ebooks1.books = data.content;

        console.log(response);
      })
    })

    return {
      ebooks,
      ebooks2: toRef(ebooks1, "books")
    }

  }
});
</script>


写回答

1回答

甲蛙

2021-05-10

ref主要用来绑定响应式变量,即页面展示的数据和js变量的绑定,比如拿到后端的列表数据ebooks,这些数据需要显示到页面上,那么ebooks就可以用ref定义

0
1
qq_蓝骏毅_04076633
非常感谢!
2021-05-11
共1条回复

Spring Boot+Vue3前后端分离,实战wiki知识库系统

一课掌握前后端最火框架,更有职场竞争力

2524 学习 · 1671 问题

查看课程