zoukankan      html  css  js  c++  java
  • jQ刚转vue时,使用this遇到的问题

    在两个页面中创建函数,并且调用一个函数中能够获取到代表vue实例的this,而另一个却获取不到

    页面1:

    1 <button id="login" v-text="$t('m.btn_0001')" @click="submit(form)"></button>
     1 export default {
     2   name: 'Login',
     3   data () {
     4     return {
          form: {}
    5 } 6 }, 7 components: {}, 8 methods: { 9 'submit': login 10 } 11 }
    1 // 点击登录
    2 function login (Para) {
    3   console.log(this) // vue实例
    4 }

    页面2--在vue实例创建后立马执行函数:

     1 export default {
     2   name: 'ProjectList',
     3   data () {
     4     return {
     5     }
     6   },
     7   created () {
     8     this.getProjectList() // 函数中this 指向vue实例
     9     getProjectList2(this) // 函数中this 为undefined,th为vue实例
    10   },
    11   methods: {
    12     'getProjectList': getProjectList
    13   },
    14   computed: {
    15   }
    16 }
    17 
    18 function this.getProjectList () {
    19   console.log(this)  
    20 }
    21 
    22 function this.getProjectList2 (th) {
    23   console.log(th)
    24   console.log(this)  
    25 }

    2021-4-22 重新查看当时的文章


     刚学习使用vue, 不习惯直接把函数放在methods里面. 放在methods对象里啥事没有

  • 相关阅读:
    ES6常用语法
    nodejs中exports与module.exports的区别
    CSS animation动画
    CSS user-select文本是否可复制
    VUE 滚动插件(better-scroll)
    VUE 父组件与子组件交互
    CSS div内文字显示两行,超出部分省略号显示
    linux下使用tar命令
    linux fdisk命令使用
    关于SUID、SGID、Sticky
  • 原文地址:https://www.cnblogs.com/whitewen/p/9290136.html
Copyright © 2011-2022 走看看