LoginSignup
1
0

More than 5 years have passed since last update.

OnsenUI何故かうまく動かないリスト

Posted at

v-forで何故か追加されない(追加はされてるけどpage__contentと同じ階層のところに追加されるので変なことになってしまう)
何故かだめ(v-ons-page直下でv-for使ったらだめ???)

index.html
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://unpkg.com/onsenui/css/onsenui.css">
<link rel="stylesheet" href="https://unpkg.com/onsenui/css/onsen-css-components.min.css">
<script src="https://unpkg.com/onsenui/js/onsenui.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script>
<script src="https://unpkg.com/vue-onsenui"></script>
<script>
    ons.ready(function() {
        new Vue({
            el: '#app',
            template: '#main',
            data() {
                return ({
                    count: 3,
                    todos: [
                        {text: 1},
                        {text: 2},
                        {text: 3},
                    ],
                });
            },
            methods: {
                addList() {
                    this.count++;
                    this.todos.push({text: this.count});
                }
            }
        });
    });
</script>
</head>
<body>
<template id="main">
    <v-ons-page>
        <ons-button @click="addList">
            リストを増やす
        </ons-button>
        <div v-for="data in todos">
            {{ data.text }}
        </div>
    </v-ons-page>
</template>
<div id="app"></div>
</body>
</html>

こうするとOK

index.html
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://unpkg.com/onsenui/css/onsenui.css">
<link rel="stylesheet" href="https://unpkg.com/onsenui/css/onsen-css-components.min.css">
<script src="https://unpkg.com/onsenui/js/onsenui.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script>
<script src="https://unpkg.com/vue-onsenui"></script>
<script>
    ons.ready(function() {
        new Vue({
            el: '#app',
            template: '#main',
            data() {
                return ({
                    count: 3,
                    todos: [
                        {text: 1},
                        {text: 2},
                        {text: 3},
                    ],
                });
            },
            methods: {
                addList() {
                    this.count++;
                    this.todos.push({text: this.count});
                }
            }
        });
    });
</script>
</head>
<body>
<template id="main">
    <v-ons-page>
        <ons-button @click="addList">
            リストを増やす
        </ons-button>
        <div>
            <div v-for="data in todos">
                {{ data.text }}
            </div>
        </div>
    </v-ons-page>
</template>
<div id="app"></div>
</body>
</html>

1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0