Created()挂钩在导航时始终有效

时间:2019-02-15 21:00:35

标签: nativescript nativescript-vue

可以帮助我。 当我进行导航时,created()挂钩总是发生。例如,我首先从Step1移到Step2,会发生created()Step2钩子(但不会发生destroy()Step1钩子),当我从Step2返回Step1时,created()Step1钩子会再次通过。

日志:

[MEIZU M3s]: 'Step 1 created.'
[MEIZU M3s]: 'Step 2 created.'
[MEIZU M3s]: 'Step 1 created.'

谢谢

Step1.vue

<template>
    <Page class="page">
        <ActionBar title="Home" class="action-bar" />
        <StackLayout>
            <Label text="Welcome to step 1!" />
            <Button text="Thanks! Step 2 please." @tap="next" />
        </StackLayout>
    </Page>
</template>

<script>
import Step2 from './Step2'

export default {
    created() {
        console.log('Step 1 created.')
    },

    destroyed() {
        console.log('Step 1 destroyed.')
    },

    methods: {
        next() {
            this.$navigateTo(Step2)
        },
    }
};
</script>

Step2.vue

<template>
    <Page class="page">
        <ActionBar title="Home" class="action-bar" />
        <StackLayout>
            <Label text="Welcome to step 2!" />
            <Button text="Great, time for step 1." @tap="prev" />
        </StackLayout>
    </Page>
</template>

<script>
    import Step1 from "./Step1";

    export default {
        created() {
            console.log("Step 2 created.");
        },

        destroyed() {
            console.log("Step 2 destroyed.");
        },

        methods: {
            prev() {
                this.$navigateTo(Step1);
            }
        }
    };
</script>

0 个答案:

没有答案