Vue中的属性绑定

2018-11-14  本文已影响14人  楠楠_c811

知识点:属性绑定和简写形式

<!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>属性绑定</title>
  <!-- 在head里面引入,避免闪屏问题 -->
  <script src="./vue.js"></script>
</head>
<body>
  <div id="root">
    <!-- 鼠标放在文字上,会显示title内容 -->
    <!-- <div title="this is hello world"> hellow world </div> -->
    <!-- 实现属性的绑定 title绑定属性中的title -->
    <!-- 使用模板指令之后,模板后面跟的内容就不是字符串而是一个JS表达式,可以任意添加内容 -->
    <div v-bind:title=" 'dell lee' + title">hellow world</div>
    <!-- v-bind: 可以缩写为: -->
    <div :title="title">hellow world</div>
  </div>
    
  <script>
    new Vue({
      el: "#root",
      data:{
        title: "this is hello world"
      }
    })
  </script>
</body>
</html>
上一篇下一篇

猜你喜欢

热点阅读