<html>
<head>
<title>Vue.js Data Binding</title>
<link rel="stylesheet" href="index.css">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id = "databinding">
<h3>{{title}}</h3>
<a href = "hreflink" target = "_blank"> Click Here </a> <br/>
<a href = "{{hreflink}}" target = "_blank">Click Here </a> <br/>
<a v-bind:href = "hreflink" target = "_blank">Click Here </a> <br/>
</div>
<script src="index.js"></script>
</body>
</html>
var vm = new Vue({
el: '#databinding',
data: {
title : "Data Binding Simple Example",
hreflink : "https://www.lidihuo.com"
}
})
html, body {
margin: 5px;
padding: 0;
}
<h3>{{title}}</h3>
<a href = "hreflink" target = "_blank"> Click Here </a> <br/>
<a href = "{{hreflink}}" target = "_blank">Click Here </a> <br/>
<a v-bind:href = "hreflink" target = "_blank">Click Here </a> <br/>
如果您单击第一个"单击此处"链接,则该href会显示为hreflink,因此不会重定向到目标网址。
如果您单击第二个"单击此处"链接,则href会显示为{{hreflink}},因此也不会重定向到目标URL。
只有第三个会重定向正确的目标URL,因为我们必须将其与 v-bind指令绑定。请参阅以下结果。
<a v-bind:href = "hreflink" target = "_blank">Click Here</a>
<a :href = "hreflink" target = "_blank">Click Here</a>
<html>
<head>
<title>Vue.js Data Binding</title>
<link rel="stylesheet" href="index.css">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<style>
.active {
background: skyblue;
}
</style>
<div id = "classbinding">
<div v-bind:class = "{active:isactive}"><b>{{title}}</b></div>
</div>
<script src="index.js"></script>
</body>
</html>
var vm = new Vue({
el: '#classbinding',
data: {
title : "HTML class binding example",
isactive : true
}
})
var vm = new Vue({
el: '#classbinding',
data: {
title : "HTML class binding example",
isactive : false
}
})
<html>
<head>
<title>Vue.js Data Binding</title>
<link rel="stylesheet" href="index.css">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<style>
.info {
color: #00529B;
background-color: #BDE5F8;
}
div {
margin: 10px 0;
padding: 12px;
}
.active {
color: #4F8A10;
background-color: #DFF2BF;
}
.displayError{
color: #D8000C;
background-color: #FFBABA;
}
</style>
<div id = "classbinding">
<div class = "info" v-bind:class = "{ active: isActive, 'displayError': hasError }">
{{title}}
</div>
</div>
<script src="index.js"></script>
</body>
</html>
var vm = new Vue({
el: '#classbinding',
data: {
title : "HTML multiple class binding example",
isActive : false,
hasError : false
}
})
var vm = new Vue({
el: '#classbinding',
data: {
title : "HTML multiple class binding example",
isActive : true,
hasError : false
}
})
var vm = new Vue({
el: '#classbinding',
data: {
title : "HTML multiple class binding example",
isActive : false,
hasError : true
}
})
<div v-bind:class="[activeClass, errorClass]"></div>
<html>
<head>
<title>Vue.js Data Binding</title>
<link rel="stylesheet" href="index.css">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<style>
.info {
color: #00529B;
background-color: #BDE5F8;
}
div {
margin: 10px 0;
padding: 12px;
font-size : 25px;
}
.active {
color: #4F8A10;
background-color: #DFF2BF;
}
.displayError{
color: #D8000C;
background-color: #FFBABA;
}
</style>
<div id = "classbinding">
<div v-bind:class = "[infoclass, errorclass]">{{title}}</div>
</div>
<script src="index.js"></script>
</body>
</html>
var vm = new Vue({
el: '#classbinding',
data: {
title : "Multiple classes with array example",
infoclass : 'info',
errorclass : 'displayError'
}
})
<div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }"></div>
data: {
activeColor: 'red',
fontSize: 30
}
<div v-bind:style="styleObject"></div>
data: {
styleObject: {
color: 'red',
fontSize: '30px'
}
}
<html>
<head>
<title>Vue.js Data Binding</title>
<link rel="stylesheet" href="index.css">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id = "databinding">
<div v-bind:style = "{ color: activeColor, fontSize: fontSize + 'px' }">{{title}}</div>
</div>
<script src="index.js"></script>
</body>
</html>
var vm = new Vue({
el: '#databinding',
data: {
title : "Inline style Binding Example",
activeColor: 'red',
fontSize :'30'
}
})
<html>
<head>
<title>Vue.js Data Binding</title>
<link rel="stylesheet" href="index.css">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id = "databinding">
<div v-bind:style = "styleobj">{{title}}</div>
</div>
<script src="index.js"></script>
</body>
</html>
var vm = new Vue({
el: '#databinding',
data: {
title : "Inline style Binding Example-2",
styleobj : {
color: 'red',
fontSize :'30px'
}
}
})