新创建一个html,利用之前学过的组件注册完成渲染
<!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>Document</title>
</head>
<body>
<div id='app'>
<login></login>
<div>
<script src='./js/vue.js'></script>
<script>
const login = {
template : '<h1>这是一个登录组件</h1>'
}
const vm = new Vue({
el : '#app', // vue实例控制的区域,称为 挂载元素
data : {},
methods: {},
components : {
login
}
})
</script>
</body>
</html>
使用render函数也可以渲染组件
<!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>Document</title>
</head>
<body>
<div id='app'>
<p>3333</p>
<div>
<script src='./js/vue.js'></script>
<script>
const login = {
template : '<h1>这是一个登录组件</h1>'
}
const vm = new Vue({
el : '#app', // vue实例控制的区域,称为 挂载元素
data : {},
methods: {},
render(createElement) {
return createElement(login)
},
})
</script>
</body>
</html>