<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script>
</head>
<body>
<div id="demo">
<button @click="switchshow">点击切换图片</button> {{show}}
<child :show="show">
</child>
</div>
<script>
Vue.component('child',{
props:['show'],
render:function(createElement){
var imgsrc
if(this.show){
imgsrc='img/01.jpg'
}else{
imgsrc='img/02.jpeg'
}
return createElement('img',{
attrs:{
src:imgsrc,
sss:"sss"
},
style:{
height:'200px',
}
})
}
})
var app = new Vue({
el: '#demo',
data: {
show:true
},
methods:{
switchshow:function(){
this.show=!this.show
}
}
})
</script>
</body>
</html>
复制代码
呈现结果