PHP前端开发

适合初学者的 VueJs VueJs 部分创建、导入和使用组件

百变鹏仔 3天前 #JavaScript
文章标签 组件

创建您的第一个组件


什么是组件?
组件是 vue 应用程序的构建块。每个组件都有自己的功能和视图,组件可以在整个应用程序中重用。组件的一个示例是可以在不同页面上访问的导航栏。

创建基本组件

<template><div>    <h1>hello, world!</h1>  </div></template><script>export default {  name: 'helloworld'}</script><style scoped>h1 {  color: blue;}</style>
<template><div id="app">    <helloworld></helloworld></div></template><script>import HelloWorld from './components/HelloWorld.vue'; //adjust according to the path to your componentexport default {  components: {    HelloWorld  }}</script>

现在您应该能够看到 app.vue 组件中渲染的 helloworld 组件。