gpt-3.5-turbo-0301· OpenAI
WildChat-4.8M (AI2)
作为一位前端, 现在需要使用uniapp 开发app, 请写一个标准的可复用组件
- User
作为一位前端, 现在需要使用uniapp 开发app, 请写一个标准的可复用组件
- Assistant
以下是一个标准的可复用组件示例:
<template> <view :class="['my-custom-component', className]"> <view class="header">{{ header }}</view> <slot /> </view> </template> <script> export default { name: 'MyCustomComponent', props: { header: String, className: { type: String, default: '', }, }, }; </script> <style> .my-custom-component { background-color: #f8f8f8; border: 1px solid #ccc; padding: 15px; } .header { font-size: 18px; font-weight: bold; margin-bottom: 10px; } </style>这个可复用组件可以接受两个属性:
header和className。使用时,只需要在需要这个组件的地方引入并传入对应属性即可。例如:
<my-custom-component header="Hello world" class="my-class"> <text>This is the content of the component</text> </my-custom-component>这个组件将会展示一个带有标题的灰色框,并显示内容。标题和样式都可以通过属性来控制。