[英]Vue JS cannot set property of innerHTML of null
I am trying to display my array as well as display it after applying array methods to it我正在尝试显示我的数组并在对其应用数组方法后显示它
<template>
<div>
<div id="demo"></div>
<div id="demo1"></div>
</div>
</template>
<script>
const formulaOneTeams = ["Red Bull", "Mercedes", "Ferrari", "Mclaren", "Aston Martin", "Alpine Racing", "Haas", "Williams", "Alpha Tauri", "Alfa Romeo"];
document.getElementById("demo").innerHTML = formulaOneTeams;
document.getElementById("demo1").innerHTML = formulaOneTeams.join(" * ");
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
As mentioned see the official Documentation on single file components .如前所述,请参阅有关单文件组件的官方文档。
<template>
<div id="my-component">
<div>{{formulaOneTeams}}</div>
<div>{{formulaOneTeams.join(" * ")}}</div>
</div>
</template>
<script>
export default {
data: () => {
return {
formulaOneTeams: [
"Red Bull",
"Mercedes",
"Ferrari",
"Mclaren",
"Aston Martin",
"Alpine Racing",
"Haas",
"Williams",
"Alpha Tauri",
"Alfa Romeo",
]
}
},
}
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.