Asked thg 2 21, 2024 9:37 SA 343 0 2
  • 343 0 2
0

Lỗi không tìm thấy role khi code Vue

Share
  • 343 0 2

Chào mọi người. Lâu lắm không gặp. Mình có bị vướng mắc khi code như sau: Mình có 1 component định nghĩa ở dưới:

<template>
  <div class="content">
    <v-row class="d-flex overflow-auto">
      <v-col cols="12" sm="2" class="align-start">
        <v-sheet class="ma-2 pa-2">
          <v-btn :append-icon="message.role === 'user' ? 'mdi-account' : 'mdi-assistant'">{{ message.role }}</v-btn>
        </v-sheet>
      </v-col>
      <v-col cols="12" sm="10" class="align-self-center">
        <v-sheet class="ma-2 pa-2">
          <pre v-html="message.content" class="preWrap"></pre>
        </v-sheet>
      </v-col>
    </v-row>
  </div>
</template>

<script>
export default {
  name: 'ChatMessage',
  props: ['msg']
}
</script>

<style scoped>
.content {
  flex: 1;
}
.preWrap {
  white-space: pre-wrap;
}
</style>

Nhưng khi biên dịch code và chạy thì báo là không tìm thấy role. Mình code bị sai ở đâu nhỉ?

Nếu cần điều tra thêm thì mình gửi các bạn pull request ở dưới đây:

https://github.com/BlazingRockStorm/gemini-chat-vue/pull/1

2 ANSWERS


Answered thg 2 21, 2024 9:49 SA
Accepted
+4

B thay message.role bằng msg.role

Prop của b ở component ChatMessage.vue là msg nhưng bạn đang dùng là message

Share
Avatar Hoàng Đức Quân @devil_boom_129
thg 2 21, 2024 9:53 SA

ok thanks nhé. quên mất

0
| Reply
Share
thg 2 22, 2024 3:09 SA

Chịu luôn.

0
| Reply
Share
Avatar PHAM HIEU @pviethieu
thg 2 22, 2024 6:40 SA

khoc

0
| Reply
Share
Avatar xuan chinh @xuanchinhtdt
thg 4 25, 2024 9:20 SA

ảo thật đấy =))

0
| Reply
Share
Answered thg 2 21, 2024 9:58 SA
0

bạn dùng Vue2 đúng k, mình thấy bạn chưa khai báo message ở props nên dùng message.role sẽ báo không tìm thấy role

Share
Viblo
Let's register a Viblo Account to get more interesting posts.