[Vue.js] Table的Checkbox全選打勾範例

by ShadowKao

HTML

<!DOCTYPE html>
<html lang="utf-8">
<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>測試頁</title> 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <style type="text/css">
        body {
            padding-top: 30px;
        }
    </style>
</head>
<body>
    <div class="container" id="myApp">
        <div class="row">

            <form method="post" action="/">
                <div class="form-group col-xs-12">
                    <table class="table table-bordered table-striped table-hover">
                        <thead>
                            <tr>
                                <th>
                                    全選
                                    <input type="checkbox" name="chk_all" v-model="chk_all" v-on:change="Chk_AllEvent" />
                                </th>
                                <th>
                                    假資料
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            <!--模擬資料後端動態產出,不使用v-for是因為通常迴圈中有複雜的邏輯需要靠後端處理,v-for不足以應付-->
                                <tr>
                                    <td>
                                        <input type="checkbox" name="chklist" 
                                               value="Jack" v-model="checkedValues"   />
                                    </td>
                                    <td>
                                        Jack  男 打字員
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <input...