Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

vue3.0 reactive([1,2,3]) 的数组怎么在tempalte里面渲染?

### VUE3.0 reactive([])的数组是Proxy,这种数据无法用v-for渲染,不清楚怎么解决

### 问题出现的环境背景及自己尝试过哪些方法

### 相关代码

<template>
   <ul class="peoples mt20">
            <li v-for="(item, index) in forPeopleList" :key="index" >
              <div class="words">{{item}}</div>
            </li>
          </ul>
</template>
setup () {
  let forPeopleList = reactive([1,2,3])
  return { 
    ...toRef(forPeopleList)
  }
}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

https://codesandbox.io/s/mode...

<template>
  <ul class="peoples mt20">
    <li v-for="(item, index) in forPeopleList" :key="index">
      <div class="words">{{ item }}</div>
    </li>
  </ul>
</template>

<script>
import { reactive } from "vue";
export default {
  name: "App",
  setup() {
    let forPeopleList = reactive([1, 2, 3]);
    return {
      forPeopleList,
    };
  },
};
</script>

<style>
</style>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...