<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
</head>
<style>
</style>
<body>
<template id='tmp'>
<button v-bind:style='getStyle(type)'>{{title}}</button>
</template>
<div id="app">
<!--使用定义好的全局组件-->
<tom-button title="hello" type='success'></tom-button>
<tom-button title="Angularjs" type='danger'></tom-button>
<tom-button title="Angularjs" type='normal'></tom-button>
</div>
</body>
<script type="text/javascript">
// 定义全局组件,两个参数:1,组件名称。2,组件参数
Vue.component("tom-button",{
template:'#tmp',
props:['title', 'type'],
methods: {
getStyle(type) {
console.log(type);
if (type=='success')
return {border: 'green 2px solid'}
if (type=='danger')
return {border: 'red 2px solid'}
return {border: 'gray 2px solid'}
}
}
})
var app = new Vue({
el:"#app"
})
</script>
</html>
vue v-bind:style 方法传参改变button颜色!
最新推荐文章于 2024-05-29 18:55:00 发布