vue 中的小知识点

1)使用is解决小bug

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.5.21/dist/vue.js"></script>
  </head>
  <body>
    <div id="root">
      <table>
        <tbody>
          <tr is="row"></tr>
          <tr is="row"></tr>
        </tbody>
      </table>

    </div>

    <script>
    Vue.component('row',{
      template:'<tr><td>{{content}}</td></tr>',
      data(){
        return{
          content:'this is row'
        }

      }
    })
    var vm = new Vue({
      el:'#root'
    })
    </script>
  </body>
</html>

2)给组件绑定原生事件

<body>
	<div id="root">
		<child @click.native="handleClick"></child>
	</div>

	<script type="text/javascript">
		Vue.component('child',{
			template:"<div>child</div>"
		})

		var vm= new Vue({
			el:"#root",
			methods:{
				handleClick:function(){
					alert("click")
				}
			}
		})
	</script>
</body>

  

原文地址:https://www.cnblogs.com/xuwupiaomiao/p/12070830.html