I want to passing a variable and read a js file from vue. I already testing it with html only it works, just need too declare in the head of html. But how it works in vue?
here's the javascript file that i want to read via vue component, and i want to passing a variable from a component to this file
document.addEventListener('DOMContentLoaded', () => {
const userGrid = document.querySelector('.grid-user') //done
const computerGrid = document.querySelector('.grid-computer') //done
const displayGrid = document.querySelector('.grid-display')
const ships = document.querySelectorAll('.ship')
createBoard(userGrid, userSquares)
createBoard(computerGrid, computerSquares)
function startSinglePlayer() {
generate(shipArray[0])
generate(shipArray[1])
generate(shipArray[2])
generate(shipArray[3])
generate(shipArray[4])
startButton.addEventListener('click', () => {
setupButtons.style.display = 'none'
playGameSingle()
})
}
//Create Board
function createBoard(grid, squares) {
for (let i = 0; i < width*width; i++) {
const square = document.createElement('div')
square.dataset.id = i
grid.appendChild(square)
squares.push(square)
}
}
........code
})
i already try to use like this
mounted() {
const plugin = document.createElement("script");
plugin.setAttribute(
"src",
"//api.myplugincom/widget/mykey.js"
);
plugin.async = true;
document.head.appendChild(plugin);
}```
but the code didn't work.
*when i only use html file not vue it works.