admin管理员组文章数量:1431718
I am migrating my vue 2 application into vue 3. While exploring position api, i came to know about ref function in setup hook which is replacing data function of option api.
In vue 2:
data() {
return {
cntmap: new Map()
}
}
I am not sure how to initialize it in ref function of setup hook. I have started learning vue 3.
I am migrating my vue 2 application into vue 3. While exploring position api, i came to know about ref function in setup hook which is replacing data function of option api.
In vue 2:
data() {
return {
cntmap: new Map()
}
}
I am not sure how to initialize it in ref function of setup hook. I have started learning vue 3.
Share Improve this question asked Feb 21, 2022 at 12:47 learningMonklearningMonk 1,4215 gold badges19 silver badges44 bronze badges1 Answer
Reset to default 4Try like following snippet:
const { ref } = Vue
const app = Vue.createApp({
setup() {
const mapList = ref(new Map())
mapList.value.set('a', 1);
mapList.value.set('b', 2);
mapList.value.set('c', 3);
return { mapList }
}
})
app.mount('#demo')
<script src="https://unpkg./[email protected]/dist/vue.global.prod.js"></script>
<div id="demo">
<li v-for="item in mapList" :key="item">
{{ item }}
</li>
</div>
本文标签: javascriptHow to declare new map() by using ref in setup hookvue 3Stack Overflow
版权声明:本文标题:javascript - How to declare new map() by using ref in setup hook - vue 3 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745423485a2658007.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论