vue233/10-组件化开发/03-父组件与子组件/复习全局组件和局部组件.html

51 lines
1.1 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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">
这是app下的文字
<dfs></dfs>
<fds></fds>
</div>
<div id="web">
这是web下的文字
<dfs></dfs>
<fds></fds>
</div>
</body>
<script src="../../00-tools/JavaScript/vue.js"></script>
<script>
/*
全局组件与局部组件的区别
1、全局组件可以用在任何一个被vue挂载的地方而局部组件只能用在当前的挂载项内
2、全局组件的组件没有s而局部组件有s
3、全局组件类似于一个方法而局部组件类似于属性
*/
Vue.component(
'dfs',{
template:`
<h1>你好,这是全局组件</h1>
`
}
)
const app=new Vue({
el:"#app"
})
const web = new Vue({
el: "#web",
components:{
fds:{
template:`
<h2>你好,这是局部组件</h2>
`
}
}
})
</script>
</html>