A brief discussion on VUE uni-app custom components

A brief discussion on VUE uni-app custom components

1. Parent components can pass data to child components through props

2. The child component can pass data to the parent component through custom events, the parent component customizes the event, the child component triggers the parent component event, and passes the data

3. Subcomponents can define slots to allow parent components to customize the content to be displayed

4. Use easycom specifications to directly use components

page/news/news.vue

<template>
	<view>
		<view>Custom component usage specifications</view>
		<card color="red" @fclick="fclick"></card>
		<card color="yellow">Yellow component</card>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			}
		},
		methods: {
			fclick(msg){
				console.log('The parent component receives the value passed by the child component: '+msg);
			}
		}
	}
</script>

<style>

</style>

Component: components/card/card.vue

<template>
	<view :style="{background:color}" @click="zclick">
		Custom component <slot></slot>
	</view>
</template>

<script>
	export default {
		name:"card",
		props:{
			color:{
				type:String,
				default:'white'
			}
		},
		data() {
			return {
				
			};
		},
		methods:{
			zclick(){
				console.log('Clicked the subcomponent');
				this.$emit('fclick','The click event is passed to the parent component');
			}
		}
	}
</script>

<style>

</style>

Summarize

This article ends here. I hope it can be helpful to you. I also hope that you can pay more attention to more content on 123WORDPRESS.COM!

You may also be interested in:
  • Detailed explanation of the use of router-view components in Vue
  • Detailed explanation of how to use Teleport, a built-in component of Vue3
  • A brief introduction to VUE uni-app basic components
  • Detailed explanation of Vue development Sort component code
  • A detailed discussion of components in Vue

<<:  Implementation of nacos1.3.0 built with docker

>>:  Detailed tutorial for installing MySQL 8.0.22 on Redhat 7.3 (binary installation)

Recommend

How to create a table by month in MySQL stored procedure

Without going into details, let's go straight...

Teach you how to deploy Vue project with Docker

1.Write in front: As a lightweight virtualization...

Linux method example to view all information of the process

There is a task process on the server. When we us...

WeChat applet custom bottom navigation bar component

This article example shares the specific implemen...

WeChat applet realizes the nine-square grid effect

This article shares the specific code for the WeC...

How to use javascript to do simple algorithms

Table of contents 1 Question 2 Methods 3 Experime...

Basic application methods of javascript embedded and external links

Table of contents Basic application of javascript...

JS canvas realizes the functions of drawing board and signature board

This article shares the specific code of JS canva...

How to use gdb to debug core files in Linux

1.core file When a Segmentation fault (core dumpe...

Solution to nginx hiding version number and WEB server information

Nginx can not only hide version information, but ...

A brief discussion on JS regular RegExp object

Table of contents 1. RegExp object 2. Grammar 2.1...

Script to quickly list all host names (computer names) in the LAN under Linux

Recently, I have a need to list all host names in...

An article to teach you HTML

If you are not committed to becoming an artist, t...