Article From:https://www.cnblogs.com/studysuper/p/9971063.html

Some simple state management can be achieved by creating storage patterns that contain shared data storage between components.
Stores can manage the state of an application and the methods responsible for changing it.

//Define Store StorageExport const stroe = {State: {Numbers: [1, 2, 3]}AddNumber (new Number) {This. state. numbers. push (new Number)}}
//Define Display StorageTemplate & gt;< div>< h4> {stroeNumber} & lt; / h4>< /div>Lt; / template & gt;Script & gt;Import {stroe} from'. / Store. js'Export default {Data () {Return {StreNumber: stroe. state. numbers}}}Lt; / script & gt;Style scoped & gt;≪ / style & gt;
//Define Submit StorageTemplate & gt;< div>< input type= "text" name=""id=""v-model="number"">Button @click= "addNumber (number)" & gt; add number & lt; / button & gt;< /div>< /temPlate>Script & gt;Import {stroe} from ". / Store. js";Export default {Data () {Return{Number: ""}}Methods: {AddNumber (number) {Stre. addNumber (numb)Er)This. number =''}}}Lt; / script & gt;Style scoped & gt;Lt; / style & gt;
Link of this Article: Vue global storage

Leave a Reply

Your email address will not be published. Required fields are marked *