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

Simple implementation method of vue3 source code analysis

Table of contents Preface 🍹Preparation 🍲vue3 usag...

Detailed tutorial on how to create a user in mysql and grant user permissions

Table of contents User Management Create a new us...

Historical Linux image processing and repair solutions

The ECS cloud server created by the historical Li...

HTML Code Writing Guide

Common Convention Tags Self-closing tags, no need...

Summary of MySQL InnoDB locks

Table of contents 1. Shared and Exclusive Locks 2...

Docker nginx implements one host to deploy multiple sites

The virtual machine I rented from a certain site ...

Nginx high concurrency optimization practice

1. Necessity of Tuning​ I have always been reluct...

Mysql 5.7.17 winx64 installation tutorial on win7

Software version and platform: MySQL-5.7.17-winx6...

Small program to implement a simple calculator

This article example shares the specific code of ...

Quickly master how to get started with Vuex state management in Vue3.0

Vuex is a state management pattern developed spec...

A solution to the abnormal exit of Tomcat caused by semaphore

I'm playing with big data recently. A friend ...

Complete steps for uninstalling MySQL database

The process of completely uninstalling the MySQL ...

Solution to secure-file-priv problem when exporting MySQL data

ERROR 1290 (HY000) : The MySQL server is running ...

Nodejs converts JSON string into JSON object error solution

How to convert a JSON string into a JSON object? ...

About the problems of congruence and inequality, equality and inequality in JS

Table of contents Congruent and Incongruent congr...