"Vue.js未渲染前, 条件渲染的元素都显示出来了"的解决方法

{{ time }}

在Vue.js渲染前, 会有一瞬间显示所有条件渲染的元素, 解决此问题的方法是v-cloak, 示例代码如下

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        /* 1. 这里要加上 */
        [v-cloak] {
            display: none;
        }
    </style>
</head>

<body>
    <!--2. 加个v-cloak -->
    <div id="app" v-cloak>
        <span v-if="editing == true">
            <button>保存</button>
        </span>
        <span v-if="editing == false">
            <button>编辑</button>
        </span>
    </div>
</body>
<script src="https://static.class4ever.com/vuejs/v2.6.10/vue.min.js"></script>
<script src="/static/plugins/layui/layui.all.js"></script>
<script>
    //启动vue
    const app = new Vue({
        el: '#app',
        data: {
            editing: true
        }
    })
</script>

</html>

这样就不会显示那一瞬间了