当前位置:网站首页>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>
边栏推荐
- You haven't connected to the proxy server. There may be a problem or the address is incorrect (how to check the proxy server IP)
- JVM memory model
- 数据湖(二十):Flink兼容Iceberg目前不足和Iceberg与Hudi对比
- Ali II: what if the AOF file in redis is too large?
- STS download tutorial (the solution cannot be downloaded on the include official website)
- POJ1611_ The Suspects
- Bishi journey
- MySQL paging query instance_ MySQL paging query example explanation "suggestions collection"
- The strongest distributed locking tool: redisson
- J9 number theory: how long is the mainstreaming of decentralized identity?
猜你喜欢

Enjoy the luxury meta universe louis:the game, and participate in the NFT series digital collection white roll activity | tutorial

评价自动化测试优劣的隐性指标

堆

(07) flask is OK if you have a hand -- flask Sqlalchemy

Alibaba cloud RDS exception during pool initialization

What should I do if I can't see any tiles on SAP Fiori launchpad?

Chapter 10 enumeration classes and annotations

多表查询

Watermelon book chapter 3 (first & second)

Watermelon Book + pumpkin book chapter 1-2
随机推荐
Lonely young people can't quit jellycat
Interviewer: how can you close an order without using a scheduled task?
12 pictures, take you to thoroughly understand ZGC garbage collector!
XXL job parameter transfer
4. Analysis of the execution process of make modules for general purposes
堆
The bank's face recognition system was broken: a depositor was stolen 430000 yuan
Go Beginner (5)
虚拟偶像的歌声原来是这样生成的!
Openpyxl drawing radar map
Top of the tide - reading notes + excerpts + insights
V. introduction of other objectives and general options
You haven't connected to the proxy server. There may be a problem or the address is incorrect (how to check the proxy server IP)
最强分布式锁工具:Redisson
I do live e-commerce in tiktok, UK
One article to understand the index of like in MySQL
Detailed explanation of flask framework
Strictly control outdoor operation time! Foshan housing and Urban Rural Development Bureau issued a document: strengthening construction safety management during high temperature
Vi. analysis of makefile.build
Go Beginner (4)