黄子涵

传入一个数组

<!-- 即便数组是静态的,我们仍然需要 `v-bind` 来告诉 Vue -->
<!-- 这是一个 JavaScript 表达式而不是一个字符串。-->
<blog-post v-bind:comment-ids="[234, 266, 273]"></blog-post>
<!-- 用一个变量进行动态赋值。-->
<blog-post v-bind:comment-ids="post.commentIds"></blog-post>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>传入一个数组</title>
<script src="./vue.js"></script>
</head>
<body>
<div id="hzh">
<hzh-component v-bind:comment-ids="[234, 266, 273]"></hzh-component>
</div>
<script>
Vue.component('hzh-component', {
props: ['comment-ids'],
template: '<h3>评论的ID号:{{commentIds}}</h3>'
})
new Vue({
el: '#hzh',
})
</script>
</body>

image

<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>传入一个数组</title>
<script src="./vue.js"></script>
</head>
<body>
<div id="hzh">
<hzh-component v-for="post in posts" v-bind:key="post.id" v-bind:comment-ids="post.commentIds"></hzh-component>
</div>
<script>
Vue.component('hzh-component', {
props: ['commentIds'],
template: '<h3>评论的ID号:{{commentIds}}</h3>'
})
new Vue({
el: '#hzh',
data: {
posts: [
{ id: 1, commentIds: [234, 266, 273]}
]
}
})
</script>
</body>

image

posted @   黄子涵  阅读(30)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示