首先,我们需要创建一个Vue组件。在Vue中,组件可以扩展HTML元素,使其具有动态行为和数据绑定。下面是一个简单的例子:
<template>
<div>
<h1>{
{ title }}</h1>
<p>{
{ message }}</p>
</div>
</template>
<script>
export default {
name: 'MyComponent',
props: {
title: String,
message: String
}
}
</script>
在这个例子中,我们创建了一个名为MyComponent的组件,它有两个属性:title和message。在模板中,我们使用双括号{ {}}来绑定属性和数据。当我们在父组件中使用这个组件时,我们可以通过传递属性来改变它的显示内容。
现在,让我们在父组件中使用这个自定义组件:
<template>
<div>
<my-component title="Hello" message="This is my custom component.