Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

254
Views
How to declare new map() by using ref in setup hook - vue 3

I am migrating my vue 2 application into vue 3. While exploring composition 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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try 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.com/vue@3.2.29/dist/vue.global.prod.js"></script>
<div id="demo">
  <li v-for="item in mapList" :key="item">
    {{ item }}
  </li>
</div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!