Vuejs2 我如何通过方法';s名称从脚本部分的数据到@click on Vue

Vuejs2 我如何通过方法';s名称从脚本部分的数据到@click on Vue,vuejs2,vuetify.js,Vuejs2,Vuetify.js,您好,我是vuetify的新手,我正在尝试使用以下数据操作是方法名称: data: () => ({ profile: [ { title: 'Profile', action: 'userProfile' }, { title: 'Settings', action: 'UserSettings' }, { divider: true }, { title: 'Log out', action: 'userLogout' }

您好,我是vuetify的新手,我正在尝试使用以下数据操作是方法名称:

data: () => ({
    profile: [
      { title: 'Profile', action: 'userProfile' },
      { title: 'Settings', action: 'UserSettings' },
      { divider: true },
      { title: 'Log out', action: 'userLogout' }
    ]
  }),


从脚本部分的数据中获得的@CLick=“item.action”之类的命令需要一个方法,而不是数据。您可以做的是,添加一个中间人函数并将
item.action
传递给中间人。然后中间人将调用预期的方法

<v-list-item-title v-text="item.title" @click="middleman(item.action)" />

...
methods: {
  middleman(action){
    switch(action){
      case 'userProfile':
         //Go to user profile
      break;
      case 'UserSettings':
         // Go to user settings
      break;
      case 'userLogout':
         // Logout the user
      break;
    }

  }
}

...
方法:{
中间人(行动){
开关(动作){
案例“userProfile”:
//转到用户配置文件
打破
案例“用户设置”:
//转到用户设置
打破
案例“userLogout”:
//注销用户
打破
}
}
}
@click="userLogout"
<v-list-item-title v-text="item.title" @click="middleman(item.action)" />

...
methods: {
  middleman(action){
    switch(action){
      case 'userProfile':
         //Go to user profile
      break;
      case 'UserSettings':
         // Go to user settings
      break;
      case 'userLogout':
         // Logout the user
      break;
    }

  }
}