zoukankan      html  css  js  c++  java
  • xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

    vue & arrow function error

    
    <template>
      <div class="home">
        <img alt="Vue logo" src="../assets/logo.png" />
        <!-- <el-button
          type="primary"
          @click="goTo(`./test-one`)">
          goto backToTop page
        </el-button> -->
        <el-button
          type="primary"
          @click="goTo(`/test-one`)">
          goto backToTop page
        </el-button>
        <el-button
          type="primary"
          @click="goTo(`/test-two`)">
          goto backTop page
        </el-button>
      </div>
    </template>
    
    <script>
    // @ is an alias to /src
    // import Tes from '@/components/Test.vue'
    
    export default {
      name: "Home",
      components: {
        // Test,
      },
      methods: {
        // goTo: (path = ``) => {
        //   console.log(`path =`, path, this);// ❌
        //   // path = /test-one undefined
        //   // [Vue warn]: Error in v-on handler: "TypeError: Cannot read property '$router' of undefined"
        //   this.$router.push(path);
        // },
        // goTo: function(path = ``) {
        //   console.log(`path =`, path, this);// ✅
        //   this.$router.push(path);
        // },
        goTo(path = ``) {
          console.log(`path =`, path, this);// ✅
          this.$router.push(path);
        },
      }
    };
    </script>
    
    
    
    
    

    vue router

    router-link === a link

    router-view === components placeholder

    
    <template>
      <div id="app">
        <div id="nav">
          <router-link to="/">Home</router-link> |
          <router-link to="/about">About</router-link>
        </div>
        <!-- 挂载点 -->
        <router-view />
      </div>
    </template>
    
    

    refs



    ©xgqfrms 2012-2020

    www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


  • 相关阅读:
    Hive、Presto、Kylin、Impala、Sparksql、Druid 区别
    HIVE vs HBASE
    mysql vs mongodb
    关于MCU 开门狗要求
    JAVA转OC j2objc
    DTD文件映射
    装饰者模式(Decorator)
    Spring Boot 概述
    C语言也会短路?盘点C语言中那些令人匪夷所思的情况!
    程序员的天梯排行榜!你的理想高度在哪里?
  • 原文地址:https://www.cnblogs.com/xgqfrms/p/14065514.html
Copyright © 2011-2022 走看看