gpt-3.5-turbo-0301· openai
Suzhen/CodeChat
给一个查询的vue2页面例子,适配手机,一个文本输入,一个查询按钮,一个列表
- User
给一个查询的vue2页面例子,适配手机,一个文本输入,一个查询按钮,一个列表
- Assistant
以下是一个简单的适配手机的Vue2页面例子,具有文本输入框,查询按钮和列表:
<template> <div class="container"> <h1>商品查询</h1> <div class="form-group"> <label for="search-input">请输入商品名称:</label> <input type="text" class="form-control" id="search-input" v-model="keyword" :disabled="isLoading"> </div> <button class="btn btn-primary" @click="search" :disabled="isLoading">查询</button> <ul class="list-group mt-3" v-show="products.length > 0"> <li class="list-group-item" v-for="(product, index) in products" :key="index"> <h5>{{ product.name }}</h5> <p>价格:{{ product.price }} 元</p> <p>{{ product.description }}</p> </li> </ul> <p class="text-center mt-3" v-show="isLoading">加载中...</p> <p class="text-center mt-3" v-show="products.length === 0 && !isLoading">暂无数据</p> </div> </template> <script> export default { data() { return { keyword: '', products: [], isLoading: false }; }, methods: { search() { if (!this.keyword) { return; } this.isLoading = true; // 开始加载 // 模拟异步请求 setTimeout(() => { this.products = [ { id: 1, name: '商品1', price: 99, description: '这是一个非常好的商品1' }, { id: 2, name: '商品2', price: 199, description: '这是一个非常好的商品2' }, { id: 3, name: '商品3', price: 299, description: '这是一个非常好的商品3' } ]; this.isLoading = false; // 完成加载 }, 2000); } } }; </script> <style> .container { height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; } .form-group { width: 100%; } .btn { width: 100%; } .list-group { width: 100%; max-height: 50vh; overflow-y: scroll; } @media (min-width: 576px) { .container { width: 400px; margin: 0 auto; } } </style> - User
给一个查询的vue2页面例子,使用ant design vue控件库,适配手机,一个文本输入,一个查询按钮,一个列表,查询地址是 url.list
- Assistant
以下是一个使用 Ant Design Vue 控件库的 Vue2 页面例子,具有文本输入框、查询按钮和列表,查询地址是 url.list。
<template> <div class="container"> <a-input v-model="keyword" placeholder="请输入商品名称" :disabled="isLoading" /> <a-button type="primary" @click="search" :disabled="isLoading">查询</a-button> <a-list :bordered="false" :loading="isLoading" v-show="products.length > 0"> <a-list-item v-for="(product, index) in products" :key="index"> <a-list-item-meta :title="product.name" :description="'价格:' + product.price + '元\n' + product.description" /> </a-list-item> </a-list> <p class="text-center mt-3" v-show="isLoading">加载中...</p> <p class="text-center mt-3" v-show="products.length === 0 && !isLoading">暂无数据</p> </div> </template> <script> import { Input, Button, List } from 'ant-design-vue'; export default { components: { 'a-input': Input, 'a-button': Button, 'a-list': List, 'a-list-item': List.Item, 'a-list-item-meta': List.Item.Meta, }, data() { return { keyword: '', products: [], isLoading: false, }; }, methods: { search() { if (!this.keyword) { return; } this.isLoading = true; // 开始加载 // 使用 axios 发起异步请求 axios.get('url.list', { params: { keyword: this.keyword } }) .then((response) => { this.products = response.data; this.isLoading = false; // 完成加载 }) .catch(() => { this.isLoading = false; // 完成加载 }); }, }, }; </script> <style> .container { height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; } @media (min-width: 576px) { .container { width: 400px; margin: 0 auto; } } </style>