首页 > 其他分享 >main(调用一个公共组件)

main(调用一个公共组件)

时间:2023-02-16 21:23:14浏览次数:29  
标签:调用 name maxin js vue export 组件 import main

app.vue

<template>
	<div>
		<Student/>
		<School></School>
	</div>
</template>
<!-- 
	1.作用(mixin):将多个组件内相同的方法提取到一个混合对象
	2.如何使用:
	全局使用:在main.js中进行使用:
	import {混合变量名} from './maxin.js'
	Vue.mixin(混合变量名)
	局部使用:在Student/School中进行使用:
	import {maxin} from '../maxin.js'
	mixins:[变量名]
 -->
<script>
	import Student from './components/Student'
	import School from './components/School'
	export default{
		name:'App',
		components:{Student,School}
	}
	
</script>

<style>
</style>

  student.vue

<template>
	<div>
		<h3>学校名称:{{name}}</h3>
		<button @click="show">点我,提示学生姓名</button>
	</div>
</template>

<script>
	// import {maxin} from '../maxin.js'
	export default {
		
		name:'School',
		data(){
			return{
				name:'渲染学校'
			}
		},
		// mixins:[maxin]
	}
</script>

<style>
</style>

  scholl.vue

<template>
	<div>
		<h3>学生姓名:{{name}}</h3>
		<button @click="show">点我,提示学生姓名</button>
	</div>
</template>
<!-- 

 -->
<script>
	//局部混合
	// import {maxin} from '../maxin.js'
	export default {
		name:'Student',
		data(){
			return {
				name:'wei'
			}
		},
		//mixins:[变量名]
		// mixins:[maxin]
	}
</script>

<style>
</style>

  main.js

import Vue from 'vue'
import App from './App.vue'
//全局混合
import {maxin} from './maxin.js'
Vue.mixin(maxin)
Vue.config.productionTip = false
new Vue({
	el:'#app',
	render: h => h(App)
})

  maxin.js

export const maxin = {
	methods:{
		show(){
			alert(this.name)
		}
	}
}

  

标签:调用,name,maxin,js,vue,export,组件,import,main
From: https://www.cnblogs.com/wsx123/p/17128346.html

相关文章

  • 基于spring-boot-starter-JDBC组件的通用增删改查
    前言配合嵌入式数据库使用,比如H2,sqlite嵌入式关系型数据,很香!pom<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc......
  • vue学习之-----组件递归调用
    1、关键点2、父组件<template><div><divclass="btn-title"><el-button@click="addRule(ruleDataList.id)">添加父节点</el-button>......
  • PHP安装SOAP扩展调用webservice获取数据
    报错内容: 调用方式:   错误原因:  URL未加后缀?WSDL导致异常,加入后异常问题解决。......
  • 新装的PDK调用device不显示
    pdk安装完以后,有些用户在调用的时候显示为空,原因是pdk里面某些文件others没有read权限。   1.cp-a完整的pak路径到others的工作目录下,不能拷贝的文件就是没有权限的......
  • QT中调用不同cpp文件的变量或者函数
    有时候会遇到一个问题,在QT中,需要使用另一个文件的函数或者对象,但是没办法直接使用。一般是在其他类中想使用主类中的函数或者变量方法1:在需要使用的文件中声明这个类, ......
  • 自己封装vue echart组件 方便调用
    <template><div><divref="lineChart":style="{width:width,height:height}"></div></div></template><script>importechartsfrom'echar......
  • C#调用usb摄像头的实现方法
    C#调用usb摄像头的实现方法2022-11-0112:32Danna_Li C#这篇文章主要介绍了C#调用usb摄像头的实现方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定......
  • C# winform中调用摄像头,拍摄并保存图片!
    首先在NuGet中,下载AForge包.把这些都添加进项目中。1.命名空间和公共属性usingAForge.Video.DirectShow;usingSystem;usingSystem.Drawing;usingSystem.IO;u......
  • vue3+jsx+antd项目,ant design vue组件中日期组件的自定义格式
    目标效果实际效果关键代码,直接从react版本的antd复制的代码,并修改了,current加上了moment(current)<DatePickerdateRender={current=>{conststyle......
  • 存储过程创建、调用
    1、存储过程创建CREATEPROCEDURE存储过程名(IN|OUT|INOUT参数名参数类型,...)[characteristics...]BEGIN存储过程体END ......