• vue2之 missing param for named route "xxxx"


    场景:

    解决方法:可以做的是将其包含router-link在适当的位置v-if,以便在您的异步数据实际到达之前不会尝试渲染。

    html代码:

    <div id="app" class="container">
      <p>
        <router-link to="/foo">Go to Foo</router-link>
        <router-link to="/bar">Go to Bar</router-link>
      </p>
      <router-view></router-view>
    </div>
    
    <script  type="text/x-template" id="joke">
        <div class="container">
             bar  <br>
           <template v-if="joke"> 
               {{joke.joke}}
               <router-link :to="{name: 'joke', params: {number: joke.id}}">{{joke.id}}</router-link>
        </template>
      </div>
    </script>

    js

    const Foo = { template: '<div>foo</div>' }
    const Bar = { 
      template: '#joke',
      data () {
        return {
          joke: null
        }
      },
      methods: {
        get: function () {
          this.$http.get('https://api.icndb.com/jokes/random').then((response) => {
            this.joke = response.body.value
            console.log(this.joke)
          }, (response) => {
            console.log(response)
          });
        }
      },
      mounted () {
        this.get()
      }
    }
    const funny = {
      template: '<div> {{id}}</div>',
      computed: {
        id () {
          return this.$route.params.number
        }
      }
    }
    
    const routes = [
      { 
        path: '/foo', 
        component: Foo,
        name: 'foo'
      },
      { 
        path: '/bar', 
        component: Bar,
        name: 'bar'
      },
      {
        path: '/joke/:number',
        name: 'joke',
        component: funny
      }
    ]
    
    const router = new VueRouter({
      routes 
    })
    
    const app = new Vue({
      router
    }).$mount('#app')
  • 相关阅读:
    celery 转自:https://www.cnblogs.com/pyedu/p/12461819.html
    k8s 学习笔记
    linux 学习笔记3
    yaml initc
    vi 块操作
    curl
    知名IT互联网公司
    ajax 上传文件给webapi(带basic认证)
    C# 后台请求api
    mvc 母版页保持不刷新
  • 原文地址:https://www.cnblogs.com/raind/p/9274732.html
Copyright © 2020-2023  润新知