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

289
Views
Quiero acceder a mi matriz (que es a cambio()) dentro de un método de métodos setup()

Aquí tengo una matriz llamada Title en data() que devuelve mi matriz (los valores se agregan dinámicamente) y quiero acceder a esa matriz Title en el método onDrop() dentro setup() , pero dice que no está undefined . ¿Alguien puede ayudarme con este error?

 import Home from "./components/Home.vue"; import Section from "./components/Sections.vue"; export default { name: "App", components: { Home, Section, }, data() { return { Title: [], }; }, methods: { sectionTitle(Title) { const newSectionTitle = { Title: Title, }; this.Title.push(newSectionTitle); }, onremoveSection(Index) { this.Title.splice(Index, 1); }, }, setup() { const startDrag = (event, index) => { console.log(index); event.dataTransfer.dropEffect = "move"; event.dataTransfer.effectAllowed = "move"; event.dataTransfer.setData("TitleIndex", index); }; const onDrop = (event, indx) => { console.log(indx); const index = event.dataTransfer.getData("TitleIndex"); console.log(index); let indexToMoveFrom = index; let indexToMoveTo = indx; const shifter = (Title, indexToMoveFrom, indexToMoveTo) => { let buff = Title[indexToMoveFrom]; for (let i = indexToMoveFrom; i < indexToMoveTo; i++) { Title[i] = Title[i + 1]; } Title[indexToMoveTo] = buff; console.log(Title); }; shifter(Title, indexToMoveFrom, indexToMoveTo); }; return { startDrag, onDrop, }; }, };

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

0

Puede mover sus datos y métodos a la función de configuración:

 import { ref } from 'vue' export default { name: "App", components: { Home, Section, }, setup() { const title = ref([]) const sectionTitle = (Title) => { const newSectionTitle = { Title: Title, }; title.value.push(newSectionTitle); } const onremoveSection = (Index) => { title.value.splice(Index, 1); } const startDrag = (event, index) => { console.log(index); event.dataTransfer.dropEffect = "move"; event.dataTransfer.effectAllowed = "move"; event.dataTransfer.setData("TitleIndex", index); }; const onDrop = (event, indx) => { console.log(indx); const index = event.dataTransfer.getData("TitleIndex"); console.log(index); let indexToMoveFrom = index; let indexToMoveTo = indx; const shifter = (Title, indexToMoveFrom, indexToMoveTo) => { let buff = Title[indexToMoveFrom]; for (let i = indexToMoveFrom; i < indexToMoveTo; i++) { Title[i] = Title[i + 1]; } Title[indexToMoveTo] = buff; console.log(Title); }; shifter(Title, indexToMoveFrom, indexToMoveTo); }; return { title, startDrag, onDrop, sectionTitle, onremoveSection }; }, }; </script>
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!