2020-01-19 vue父传子2

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>Title</title>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

<style>

.container{

padding:10px;

border:1px solid red;

width:300px;

box-sizing:border-box;

margin:20px auto;

}

.container h3{

font-size:16px;

line-height:40px;

font-weight:bold;

border-bottom:1px dashed #AAA;

}

</style>

</head>

<body>

<div id="app">

<my-vote v-for="item in voteList" :title="item.title"></my-vote>

</div>













<template id="MyVoteTemplate">

<div class="container">

<h3><span v-text="title"></span>(<span>0</span>)</h3>

<vote-content></vote-content>

<vote-button></vote-button>

</div>

</template>

<template id="VoteContentTemplate">

<div class="content">

<p>支持人数:<span>0</span></p>

<p>反对人数:<span>0</span></p>

<p>支持率:<span>0%</span></p>

</div>

</template>

<template id="VoteButtonTemplate">

<div class="footer">

<button type="button" class="btn btn-primary">支持</button>

<button type="button" class="btn btn-danger">反对</button>

</div>

</template>

</body>

<script src="https://cdn.jsdelivr.net/npm/vue"></script>

<script>

const VoteContent={

template:'#VoteContentTemplate',

data(){

return {}

}

}

const VoteButton={

template:'#VoteButtonTemplate',

data(){

return {}

}

}

const MyVote={

template:'#MyVoteTemplate',

props:['title'],

data(){

return {}

},

components:{

VoteContent,

VoteButton

        },

mounted(){

//基于属性传递过来的值,只能获取使用,不能再子组件中修改(修改够会有对应得效果,子组件会重新渲染,但是控制台会报错)

// this.title='Aaa'

        }

}

let vm=new Vue({

el:'#app',

data:{

voteList:[

{id:1,title:'张三'},

{id:2,title:'李四'}

]

},

components:{

MyVote

        }

})

</script>

</html>

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • <!DOCTYPE html> Title .container{ padding:10px; border:1p...
    BAT努力阅读 1,256评论 0 0
  • ## Vue进阶 ### 一、vue实例 #### 1.一个基本的vue的实例 ```html {{title}}...
    千锋陈老师阅读 4,014评论 0 1
  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom阅读 8,008评论 0 3
  • 1. tab列表折叠效果 html: 能源系统事业部 岗位名称: 工作地点 岗位名...
    lilyping阅读 5,927评论 0 1
  • 明天又要启程。离别在即,妈妈和姐姐的生日,提前两天过了。 出门在外,能在妈妈生日时候回家的机会不多。 姐姐本来不在...
    驿路笔记阅读 1,189评论 0 3

友情链接更多精彩内容