<!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>x-template的使用学习</title>
</head>

<body>
    <div id='app'>
        <my-component></my-component>
    </div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script>

 <!-- 组件内容 id为 my-component   type 为text/x-template  -->
<script type='text/x-template' id='my-component'>
<div>  这是组件内容</div>
</script>

<script>
    // 声明一个组件 my-component 引入id 为my-component
    Vue.component('my-component', {
        template: '#my-component'
    })

    var app = new Vue({
        el: '#app'
    })
</script>

</html>

github code 地址

Logo

前往低代码交流专区

更多推荐