Can vue bind global properties?

clipboard.png

A toash component, the time I set is 1800 milliseconds, and a project has N pages using toash. If one day the product asks me to change it to 3000 milliseconds, then I have to change it one by one. Is there a good solution?

<toast
    v-model="msg"
    type="text"
    :time="1800"
    position="top"
    text="">
</toast>

the easiest way is for you to set

in the component.
props:{
    time: {
        type: Number,
        default: 1800
    }
}

it is best to set a global variable. Then make a

data.js
export const TOAST_TIME = 1800
import {TOAST_TIME} from '........./data'
props:{
    time: {
        type: Number,
        default: TOAST_TIME
    }
}

then you can change it if it is not 1800 special when you pass it in


1. Create a js: of configuration variables

export const TIME = 1800

2. Import this file variable in the required vue file

import {TIME} from './config.js'

in main.js , write window.TOAST_TIME = 1800
also use window.TOAST_TIME directly to OK
simple and rude
Hey, hey

Don't be misled by me, landlord

the elegant implementation is definitely to package the toash and make it the components, of vue, so that you can write once in this component, introduce the component where you want to use it, and make some parameters into props, that can be customized in every place where the component is called. Wouldn't it be nice


you can use layer.msg ()


< toast

v-model="msg"
type="text"
:time="time"
position="top"
text="">

< / toast >

as a child component, the time when the props receives the time parent component passed by the parent component can introduce a global variable, which can be defined in main.js window.TOAST_TIME = 1800

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e8d948-4e639.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e8d948-4e639.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?