Vue Template的三种写法
第一种,直接写在构造器里的template选项中:<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content=
·
第一种,直接写在构造器里的template选项中:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app">
</div>
<script src="./node_modules/vue/dist/vue.js"></script>
<script>
new Vue({
el: '#app',
template: `
<div>模板文件</div>
`
});
</script>
</body>
</html>
第二种:写在template标签中,像是在写HTML代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app">
<template id="demo">
<div>模板文件</div>
</template>
</div>
<script src="./node_modules/vue/dist/vue.js"></script>
<script>
new Vue({
el: '#app',
template: '#demo'
});
</script>
</body>
</html>
第三种,写在script标签中:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app"
</div>
<script src="./node_modules/vue/dist/vue.js"></script>
<script type="x-template" id="demo">
<div>模板文件</div>
</script>
<script>
new Vue({
el: '#app',
template: '#demo'
});
</script>
</body>
</html>
更多推荐
已为社区贡献12条内容
所有评论(0)