Answer the question
In order to leave comments, you need to log in
How to pass variable from vanilla js to Vue object?
For example, I declared a variable in js:
Below (the Vue object is declared in the code itself):
PS
Simply declaring in data: nums[], is not an option for me, since I need an already formed array obtained earlier.
let nums = [1, 2, 3];
let menu_change = new Vue({some code})
Answer the question
In order to leave comments, you need to log in
let nums = [1, 2, 3];
// 100 000 000 строк кода
let menu_change = new Vue({
// 100 000 000 строк кода
methods: {
showArr(){
console.log( nums )
}
}
// 100 000 000 строк кода
})
https://ru.vuejs.org/v2/api/#provide-inject
const nums = [1, 2, 3];
// Добавляем провайдера
const app = new Vue({
provide: {
nums,
},
});
// Внедряем в компонентах
// дочерний компонент внедряет 'nums'
const Children = {
inject: ['nums'],
created () {
console.log(this.nums) // => [1, 2, 3]
}
// ...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question