+
95
-

Vuex的作用是什么?

vue

请问Vuex的作用是什么?怎么用?

网友回复

+
15
-

Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式。它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化。Vuex 也集成到 Vue 的官方调试工具 devtools extension,提供了诸如零配置的 time-travel 调试、状态快照导入导出等高级调试功能。

看一个示例,通过vuex实现组件之间的值传递效果

<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="UTF-8">


    <style>
@import url(https://fonts.googleapis.com/css?family=Open+Sans:400,300,600);
:root {
        font-size: 16px;
    }

        * {
            box-sizing: border-box;
        }

        html, body {
            height: 100%;
            margin: 0;
            padding: 0;
        }

        #app {
            min-height: 100%;
            display: flex;
            flex-direction: column;
        }
        #app .parent, #app .split {
            display: flex;
            height: 50vh;
        }
        #app .parent {
            border-bottom: 1px solid #ddd;
            padding: 1rem;
            align-items: center;
            justify-content: center;
            text-align: center;
            flex-direction: column;
        }
        #app .parent small {
            color: #999;
        }
        #app .parent .editor {
            display: flex;
            align-items: center;
            margin-top: 1.5rem;
        }
        #app .parent .editor .btn {
            border-top-left-radius: 0;
            border-bottom-left-radius: 0;
        }
        #app .parent .editor input {
            border-top-right-radius: 0;
            border-top-right-radius: 0;
        }
        #app .split .child {
            width: 50%;
            padding: 1rem;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-direction: column;
        }
        #app .split .child:last-of-type {
            border-left: 1px solid #ddd;
        }
        #app .split .child h2 {
            font-weight: 400;
        }
    </style>



</head>

<body>
    <div id="app">
        <div class="parent...

点击查看剩余70%

我知道答案,我要回答