当前位置:网站首页>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
边栏推荐
- 【FPGA帧差】基于VmodCAM摄像头的帧差法目标跟踪FPGA实现
- Image style migration cyclegan principle
- 组件的自定义事件②
- How to choose a product manager course when changing to a product manager?
- Browser local storage
- 【LINGO】求解二次规划
- The game is real! China software cup releases a new industrial innovation competition, and schools and enterprises can participate in it jointly
- Jax's deep learning and scientific computing
- 【剑指offer&牛客101】中那些高频笔试,面试题——链表篇
- C # read and write customized config file
猜你喜欢

C # read and write customized config file

Système de gestion de l'exploitation et de l'entretien, expérience d'exploitation humanisée

JSP - paging

Why did grayscale fall from the altar?

未来互联网人才还稀缺吗?哪些技术方向热门?

DC-4 target

Image style migration cyclegan principle

Redisson utilise la solution complète - redisson Documents officiels + commentaires (Partie 1)

【LINGO】求无向图的最短路问题

Challenges faced by operation and maintenance? Intelligent operation and maintenance management system to help you
随机推荐
ctfshow-web355,356(SSRF)
ctfshow-web352,353(SSRF)
Unity2021-Scene视图中物体无法直接选中的解决办法
redisson使用全解——redisson官方文档+注释(下篇)
【FPGA帧差】基于VmodCAM摄像头的帧差法目标跟踪FPGA实现
Félicitations pour l'inscription réussie de wuxinghe
Operation and maintenance management system, humanized operation experience
【LINGO】求七个城市最小连线图,使天然气管道价格最低
在长城证券上做基金定投安全吗?
Summary of the concept and advantages of 5g massive MIMO
【目标检测】目标检测界的扛把子YOLOv5(原理详解+修炼指南)
浏览器本地存储
Servlet 和 JSP 中的分页
Mysql与Redis一致性解决方案
Which securities company is better or safer for mobile phone account opening
Open source! Wenxin large model Ernie tiny lightweight technology, accurate and fast, full effect
Image style migration cyclegan principle
Is it safe to buy funds on the brokerage account
【电气介数】电气介数及考虑HVDC和FACTS元件的电气介数计算
【推荐技术】基于协同过滤的网络信息推荐技术matlab仿真