当前位置:网站首页>Mixin\ plug in \scoped style
Mixin\ plug in \scoped style
2022-07-27 12:34:00 【moonbaby1】
One .mixin
Also known as mixing
function : The configuration shared by multiple components can be extracted into a mixed object
Usage method :
The first step is to define the blend , for example :
{
data(){...}
methods:{}
......
}
Step 2 use blending , for example
1. The whole thing is in :Vue.mixin(xxx)
2. To mix in partially :mixins:['xxx']
MyStudent.vue
<template>
<div>
<h2 @click = "showName"> The student's name :{
{name}}</h2>
<h2> Student gender :{
{sex}}</h2>
</div>
</template>
<script>
import {hunhe} from '../mixin'
export default {
name:"MyStudent",
data(){
console.log(this)
return {
name:' Zhang San ',
sex:' male '
}
},
mixins:[hunhe]
}
</script>
MySchool.vue
<template>
<div>
<h2 @click = "showName"> School name :{
{name}}</h2>
<h2> School address :{
{address}}</h2>
</div>
</template>
<script>
import {hunhe} from '../mixin'
export default {
name:"MySchool",
data(){
console.log(this)
return {
name:' Silicon Valley ',
address:' Beijing ',
x:666
}
},
mixins:[hunhe],
mounted(){
console.log(" How do you do !!!!!!")
}
}
</script>
mixin.js
export const hunhe= {
data() {
return {
x:100,
y:200
}
},
methods: {
showName(){
alert(this.name)
}
},
mounted() {
console.log(' How do you do !')
},
}
// export const hunhe2 = {
// data() {
// return {
// x:100,
// y:200
// }
// },
// }main.js
import Vue from 'vue'
import App from './App.vue'
import {hunhe} from './mixin'
Vue.config.productionTip = false
Vue.mixin(hunhe)
new Vue({
el:'#app',
render: h => h(App)
})App.vue Just import student and school components into
(1)data Data mixing , If not , Mixed with , Additional data . If there was this variable , Mixing also has variables , In the original component data Variable dominated
(2) Life cycle mounted in , If the mixed and original components share functions , Both , And the functions of the original component are executed first . Execute after mixing
Two . plug-in unit

|-- App.vue
|-- components
| |-- School.vue
| `-- Student.vue
|-- main.js
`-- plugins.jsplugins.js
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
Introducing plug-ins ,use plug-in unit
// 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)
})stay school and student Used in components

Filters and methods from plug-ins
3、 ... and 、scoped style
effect : Let the style take effect locally , To prevent conflict
How to write it :<style scoped>
problem :
School Component's demo The style is sky blue ,student The same name of the component demo The style is orange

If in App.vue First introduce school, For blue , To introduce student It's orange


After modifying the reference order , It's sky blue again
summary : After the style has the same name , Later generations live in , Configure according to the latter . Look at the introduction sequence
vue First introduced , Then read the configuration item , Then it comes to interface templates ( Mainly introduce )
solve
stay style After add scoped attribute , The principle is div After adding a special random value tag attribute . Make the style have a specified action threshold

View version
npm view webpack versions
npm view less-loader versionsinstall 7 Version of less-loader
npm i [email protected]You can also add lang, Appoint css perhaps less( Can be nested ). Don't write lang Default css, Yes lang Do not empty
<style lang="css" scoped>
.demo{
background-color:skyblue;
}
</style>
边栏推荐
- Keil mdk5.37 and above can add AC5 (armcc) compiler by themselves
- 最强分布式锁工具:Redisson
- Docker MySQL Usage Note
- II. Analysis of the execution process of make menuconfig
- Shake quickly to rescue the "frustrated person"
- Write and read system temporary files: createtempfile and tempfilecontent[easy to understand]
- Photoshop web design tutorial
- XXL job parameter transfer
- Complete data summary of lapsus$apt organization that stole Microsoft's source code in March 2022
- Interviewer: how can you close an order without using a scheduled task?
猜你喜欢

Julia beginner tutorial 2022

ArrayList常用方法总结

I do live e-commerce in tiktok, UK

多表查询

Set接口

Alibaba cloud RDS exception during pool initialization

II. Analysis of the execution process of make menuconfig
QT | qcheckbox of control

Self built personalized automatic quotation system to cope with changeable quotation mode

Unity 2D game tutorial
随机推荐
堆
最强分布式锁工具:Redisson
Bishi journey
Data Lake (20): Flink is compatible with iceberg, which is currently insufficient, and iceberg is compared with Hudi
Plus SBOM: assembly line BOM pbom
Simple blockchain day based on bolt database (2)
Chain representation and implementation of queues
After Party A's hard work, 49.08 million orders of China Mobile were scrapped
Openpyxl drawing radar map
Soft core microprocessor
Insert sort summary
Top of the tide - reading notes + excerpts + insights
Will causal learning open the next generation of AI? Chapter 9 Yunji datacanvas officially released the open source project of ylarn causal learning
Go Beginner (4)
概述有名内部类与匿名内部类
Transactions in MySQL
HDU1698_ Just a Hook
Binary search decision tree (average search length of binary search tree)
About the problem that the onapplicationevent method of the custom listener is executed multiple times
What should I do if I can't see any tiles on SAP Fiori launchpad?