Problems with vue-router children subcomponents

while learning, vue2x, encounters the following examples when using vue-router components:

<!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></title>
</head>

<body>
    <div id="app">
        <router-view></router-view>
    </div>
</body>
<script src="../lib/vue.js"></script>
<script src="../lib/vue-router.js"></script>
<!--  -->
<script type="text/x-template" id="content_t">
    <div>
        <div>{{field.content}}</div>
        <router-link to="/"></router-link>
    </div>
</script>
<script type="text/x-template" id="home_t">
    <div>
        <li v-for="(v,k) in news">
            <router-link :to="{name:"content_as",params:{id:v.id,index:k}}">{{v.title}}</router-link>
        </li>
        <router-view></router-view>
    </div>
</script>
<script>
    var data = [
        { id: 1, title: "", content: "nba......" },
        { id: 2, title: "", content: "......" }
    ]

    const home = {
        template: "-sharphome_t",
        data() {
            return {
                news: data
            }
        }
    }
    const content = {
        template: "-sharpcontent_t",
        data() {
            return {
                field: {}
            }
        },
        mounted() {
            var index = this.$route.params.index;
            this.field = data[index];
        }
    }

    const routeConf = [
        {
            path: "/", component: home, name: "home_as", children: [
                { path: "/content/:id", component: content, name: "content_as" }
            ]
        }
    ]

    let router = new VueRouter({
        routes: routeConf
    })

    var vm = new Vue({
        el: "-sharpapp",
        router: router
    })

</script>

</html>

encountered a problem:

clipboard.png
when switching between sports news and technology news, you can"t change it in real time. You need to click back to the home page.
I think it"s the sub-component mounted (), because it"s only mounted once. How do I modify the code to make the click take effect in real time?

Oct.14,2021

switching between the same route will not be remounted. You need to listen for route changes and do what you want


this is a sub-route switching problem https://www.jianshu.com/p/6c1.


mounted () is executed only once after binding the vue instance (which can also be understood as the first rendering of the dom element), and the switching route will not be repeated under the same component.
vue life cycle can refer to this link
Custom method in @ click event to force the page to refresh to re-mounted
you can also use watch to listen for route changes

watch: {
      $route ( newVal ) {
        this.field = data[newVal.params.index]
      }
    }
Menu