当前位置:网站首页>Atguigu---- scaffold --02- use scaffold (2)
Atguigu---- scaffold --02- use scaffold (2)
2022-07-01 07:21:00 【Zhang Shao】
ref attribute
- Used to register reference information for an element or subcomponent (id The replacement of )
- Apply to html What you get on the label is real DOM Elements , Applied on the component label is the component instance object (vc)
- Usage mode :
- Marking :
<h1 ref="xxx">.....</h1>or<School ref="xxx"></School> - obtain :
this.$refs.xxx
- Marking :
<template>
<div>
<h1 v-text="msg" ref="title"></h1>
<button ref="btn" @click="showDOM"> Click on the top of my output DOM Elements </button>
<School ref="sch"/>
</div>
</template>
<script> // introduce School Components import School from './components/School' export default {
name:'App', components:{
School}, data() {
return {
msg:' Welcome to learn Vue!' } }, methods: {
showDOM(){
console.log(this.$refs.title) // real DOM Elements console.log(this.$refs.btn) // real DOM Elements console.log(this.$refs.sch) //School Component instance objects (vc) } }, } </script>
props Configuration item
function : Let the component receive the data transmitted from the outside
To transfer data :
<Demo name="xxx"/>receive data :
The first way ( Only receive ):
props:['name']The second way ( Type of restriction ):
props:{name:String}The third way ( Type of restriction 、 Necessity of restriction 、 Specify default ):
props:{ name:{ type:String, // type required:true, // The need for default:' Lao Wang ' // The default value is } }
remarks :props Is read-only ,Vue The bottom will monitor you for props Modification of , If it's changed , A warning will be issued , If business requirements really need to be modified , Then please copy props Content to data Middle portion , Then go and modify data Data in .
<template>
<div>
<h1>{
{msg}}</h1>
<h2> The student's name :{
{name}}</h2>
<h2> Student gender :{
{sex}}</h2>
<h2> Student age :{
{myAge+1}}</h2>
<button @click="updateAge"> Try to modify the age received </button>
</div>
</template>
<script> export default {
name:'Student', data() {
console.log(this) return {
msg:' I am a student in Silicon Valley ', myAge:this.age } }, methods: {
updateAge(){
this.myAge++ } }, // Simple declaration of receipt // props:['name','age','sex'] // While receiving, the type of data is limited /* props:{ name:String, age:Number, sex:String } */ // Receive data at the same time : Make type restrictions + Specify the default value + The limits of necessity props:{
name:{
type:String, //name The type of is string required:true, //name be necessary }, age:{
type:Number, default:99 // The default value is }, sex:{
type:String, required:true } } } </script>
mixin( Mix in )
function : The configuration shared by multiple components can be extracted into a mixed object
Usage mode :
The first step is to define the blend :
{ data(){....}, methods:{....} .... }Step 2 use blending :
The whole thing is in :
Vue.mixin(xxx)
To mix in partially :mixins:['xxx']

export const hunhe = {
methods: {
showName(){
alert(this.name)
}
},
mounted() {
console.log(' How do you do !')
},
}
export const hunhe2 = {
data() {
return {
x:100,
y:200
}
},
}
// introduce Vue
import Vue from 'vue'
// introduce App
import App from './App.vue'
import {
hunhe,hunhe2} from './mixin'
// close Vue Production tips for
Vue.config.productionTip = false
Vue.mixin(hunhe)
Vue.mixin(hunhe2)
// establish vm
new Vue({
el:'#app',
render: h => h(App)
})
<template>
<div>
<h2 @click="showName"> School name :{
{name}}</h2>
<h2> School address :{
{address}}</h2>
</div>
</template>
<script> // The introduction of a hunhe // import {hunhe,hunhe2} from '../mixin' export default {
name:'School', data() {
return {
name:' Silicon Valley ', address:' Beijing ', x:666 } }, // mixins:[hunhe,hunhe2], } </script>
<template>
<div>
<h2 @click="showName"> The student's name :{
{name}}</h2>
<h2> Student gender :{
{sex}}</h2>
</div>
</template>
<script> // import {hunhe,hunhe2} from '../mixin' export default {
name:'Student', data() {
return {
name:' Zhang San ', sex:' male ' } }, // mixins:[hunhe,hunhe2] } </script>
plug-in unit
function : For enhancement Vue
The essence : contain install Method ,install The first parameter of Vue, The second parameter after is the data passed by the plug-in user .
Define plug-ins :
object .install = function (Vue, options) { // 1. Add global filter Vue.filter(....) // 2. Add global directive Vue.directive(....) // 3. Configure global blending ( close ) Vue.mixin(....) // 4. Add instance method Vue.prototype.$myMethod = function () { ...} Vue.prototype.$myProperty = xxxx }The use of plug-in :
Vue.use()
export default {
install(Vue,x,y,z){
console.log(x,y,z)
// Global filter
Vue.filter('mySlice',function(value){
return value.slice(0,4)
})
// Define global instructions
Vue.directive('fbind',{
// When an instruction is successfully bound to an element ( at first )
bind(element,binding){
element.value = binding.value
},
// When the element of the instruction is inserted into the page
inserted(element,binding){
element.focus()
},
// When the template of the instruction is parsed again
update(element,binding){
element.value = binding.value
}
})
// Define blend
Vue.mixin({
data() {
return {
x:100,
y:200
}
},
})
// to Vue Add a method to the prototype (vm and vc It'll work )
Vue.prototype.hello = ()=>{
alert(' How do you do ')}
}
}
main.js
// introduce Vue
import Vue from 'vue'
// introduce App
import App from './App.vue'
// Introducing plug-ins
import plugins from './plugins'
// close Vue Production tips for
Vue.config.productionTip = false
// application ( Use ) plug-in unit
Vue.use(plugins,1,2,3)
// establish vm
new Vue({
el:'#app',
render: h => h(App)
})
scoped style
effect : Let the style take effect locally , To prevent conflict .
How to write it :
<style scoped>
Less Use
If not installed , Just install npm i [email protected] Install the specified version
View version of npm view less-loader versions
边栏推荐
- ctfshow-web354(SSRF)
- [FPGA frame difference] FPGA implementation of frame difference target tracking based on vmodcam camera
- 北漂程序员深夜emo发帖求助:女朋友走了我很孤独 ......
- Alibaba OSS postman invalid according to policy: policy condition failed: ["starts with", "key", "test/"]
- atguigu----脚手架--02-使用脚手架(2)
- 【编程强训】删除公共字符(哈希映射)+组队竞赛(贪心)
- redisson使用全解——redisson官方文档+注释(中篇)
- JAX的深度学习和科学计算
- TodoList经典案例①
- AI视频智能平台EasyCVR设备录像出现无法播放现象的问题修复
猜你喜欢

【目标检测】目标检测界的扛把子YOLOv5(原理详解+修炼指南)

1286_FreeRTOS的任务优先级设置实现分析

Illusory and simple screen raindrop post-processing effect

Unity2021-Scene视图中物体无法直接选中的解决办法
![[lingo] solve quadratic programming](/img/4d/3f7de69943f29a71c4039299c547f7.png)
[lingo] solve quadratic programming

ctfshow-web351(SSRF)

Is it suitable for girls to study product manager? What are the advantages?

运维面临挑战?智能运维管理系统来帮您
![C language implementation [Sanzi chess game] (step analysis and implementation source code)](/img/3b/d32b46292ed20f31a6e1db97349df1.png)
C language implementation [Sanzi chess game] (step analysis and implementation source code)

Servlet 和 JSP 中的分页
随机推荐
[Shenzhen IO] precise Food Scale (some understanding of assembly language)
Why did grayscale fall from the altar?
ctfshow-web351(SSRF)
Buildreoot override mechanism
C语言实现【扫雷游戏】完整版(实现源码)
C language implementation [minesweeping game] full version (implementation source code)
关于图灵测试和中文屋Chinese room的理解
The computer has a network, but all browser pages can't be opened. What's the matter?
赌上了绩效,赢了公司CTO,我要搭DevOps平台!
【Flutter 问题系列第 72 篇】在 Flutter 中使用 Camera 插件拍的图片被拉伸问题的解决方案
熱烈祝賀五行和合酒成功掛牌
[the path of system analysts] Chapter 5: software engineering of double disk (reverse clean room and Model Driven Development)
Will Internet talents be scarce in the future? Which technology directions are popular?
【LINGO】求解二次规划
ctfshow-web355,356(SSRF)
Operation and maintenance management system, humanized operation experience
【目标检测】目标检测界的扛把子YOLOv5(原理详解+修炼指南)
ctfshow-web355,356(SSRF)
Do securities account opening affect the security of account opening
The programmer of Beipiao posted a post for help late at night: I am lonely when my girlfriend is gone