当前位置:网站首页>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
边栏推荐
- 浅谈CVPR2022的几个研究热点
- C# Newtonsoft.Json中JObject的使用
- 【计网】(一) 集线器、网桥、交换机、路由器等概念
- 热烈祝贺五行和合酒成功挂牌
- 【FPGA帧差】基于VmodCAM摄像头的帧差法目标跟踪FPGA实现
- Redisson utilise la solution complète - redisson Documents officiels + commentaires (Partie 1)
- Illusory and simple screen raindrop post-processing effect
- 手机开户选哪个证券公司比较好,哪个更安全
- Is it reliable to open an account on the compass with your mobile phone? Is there any potential safety hazard
- 如何画产品架构图?
猜你喜欢

【推荐技术】基于协同过滤的网络信息推荐技术matlab仿真

LeetCode+ 71 - 75
![[network planning] (I) hub, bridge, switch, router and other concepts](/img/7b/fcef37496517c854ac1dbfb35fa3f4.png)
[network planning] (I) hub, bridge, switch, router and other concepts

如何进入互联网行业,成为产品经理?没有项目经验如何转行当上产品经理?

Why are so many people turning to product managers? What is the development prospect of product manager?

盘点华为云GaussDB(for Redis)六大秒级能力

Mysql与Redis一致性解决方案
![[lingo] find the minimum connection diagram of seven cities to minimize the price of natural gas pipelines](/img/34/d2efae5b283cdc130d55f52cdff76d.png)
[lingo] find the minimum connection diagram of seven cities to minimize the price of natural gas pipelines
![[Tikhonov] image super-resolution reconstruction based on Tikhonov regularization](/img/49/719496e014f4766d22aba44dbed19e.png)
[Tikhonov] image super-resolution reconstruction based on Tikhonov regularization

How to draw a product architecture diagram?
随机推荐
为什么这么多人转行产品经理?产品经理发展前景如何?
运维管理系统,人性化操作体验
[chapter 72 of the flutter problem series] a solution to the problem that pictures taken in the flutter using the camera plug-in are stretched
Is it suitable for girls to study product manager? What are the advantages?
weback5基础配置详解
组件的自定义事件①
Subclasses call methods and properties of the parent class with the same name
【目标检测】目标检测界的扛把子YOLOv5(原理详解+修炼指南)
[microservice openfeign] feign's log record
How to enter the Internet industry and become a product manager? How to become a product manager without project experience?
Understanding of Turing test and Chinese Room
MySQL table partition creation method
【Tikhonov】基于Tikhonov正则化的图像超分辨率重建
C# Newtonsoft. Use of job in JSON
iNFTnews | 从《雪崩》到百度“希壤”,元宇宙30年的16件大事
在券商账户上买基金安全吗
【FPGA帧差】基于VmodCAM摄像头的帧差法目标跟踪FPGA实现
浏览器本地存储
運維管理系統,人性化操作體驗
2022制冷与空调设备运行操作国家题库模拟考试平台操作