使用微信小程序工具设计一个小程序,主要功能有: 1)用户通过下拉操作,弹出提示对话框; 2)实现3种以上不同页面跳转。 包括js、wxml、wxss代码
时间: 2024-03-12 08:48:49 浏览: 125
以下是一个简单的示例小程序,实现了您提到的功能:
app.js:
```javascript
//app.js
App({
globalData: {
userInfo: null
}
})
```
app.json:
```json
{
"pages": [
"pages/index/index",
"pages/page1/page1",
"pages/page2/page2",
"pages/page3/page3"
],
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "Demo",
"navigationBarTextStyle": "black"
},
"tabBar": {
"list": [
{
"pagePath": "pages/index/index",
"text": "首页"
},
{
"pagePath": "pages/page1/page1",
"text": "页面1"
},
{
"pagePath": "pages/page2/page2",
"text": "页面2"
},
{
"pagePath": "pages/page3/page3",
"text": "页面3"
}
]
}
}
```
index.wxml:
```xml
<!--index.wxml-->
<view class="container">
<view class="title">首页</view>
<view class="btn" bindtap="showModal">下拉提示框</view>
<view class="btn" bindtap="navigateToPage1">跳转页面1</view>
<view class="btn" bindtap="navigateToPage2">跳转页面2</view>
<view class="btn" bindtap="navigateToPage3">跳转页面3</view>
</view>
```
index.wxss:
```css
/* index.wxss */
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
}
.title {
font-size: 24px;
margin-bottom: 20px;
}
.btn {
display: block;
width: 200px;
height: 40px;
line-height: 40px;
text-align: center;
margin-bottom: 20px;
background-color: #4CAF50;
color: #fff;
border-radius: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.btn:hover {
background-color: #3e8e41;
cursor: pointer;
}
```
index.js:
```javascript
//index.js
const app = getApp()
Page({
showModal: function () {
wx.showModal({
title: '提示',
content: '这是一个模态弹窗',
success(res) {
if (res.confirm) {
console.log('用户点击确定')
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
},
navigateToPage1: function () {
wx.navigateTo({
url: '/pages/page1/page1',
})
},
navigateToPage2: function () {
wx.navigateTo({
url: '/pages/page2/page2',
})
},
navigateToPage3: function () {
wx.navigateTo({
url: '/pages/page3/page3',
})
}
})
```
page1.wxml:
```xml
<!--page1.wxml-->
<view class="container">
<view class="title">页面1</view>
<view class="btn" bindtap="navigateBack">返回首页</view>
</view>
```
page1.wxss:
```css
/* page1.wxss */
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
}
.title {
font-size: 24px;
margin-bottom: 20px;
}
.btn {
display: block;
width: 200px;
height: 40px;
line-height: 40px;
text-align: center;
margin-bottom: 20px;
background-color: #4CAF50;
color: #fff;
border-radius: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.btn:hover {
background-color: #3e8e41;
cursor: pointer;
}
```
page1.js:
```javascript
//page1.js
Page({
navigateBack: function () {
wx.navigateBack({
delta: 1
})
}
})
```
page2.wxml:
```xml
<!--page2.wxml-->
<view class="container">
<view class="title">页面2</view>
<view class="btn" bindtap="navigateBack">返回首页</view>
</view>
```
page2.wxss:
```css
/* page2.wxss */
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
}
.title {
font-size: 24px;
margin-bottom: 20px;
}
.btn {
display: block;
width: 200px;
height: 40px;
line-height: 40px;
text-align: center;
margin-bottom: 20px;
background-color: #4CAF50;
color: #fff;
border-radius: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.btn:hover {
background-color: #3e8e41;
cursor: pointer;
}
```
page2.js:
```javascript
//page2.js
Page({
navigateBack: function () {
wx.navigateBack({
delta: 1
})
}
})
```
page3.wxml:
```xml
<!--page3.wxml-->
<view class="container">
<view class="title">页面3</view>
<view class="btn" bindtap="navigateBack">返回首页</view>
</view>
```
page3.wxss:
```css
/* page3.wxss */
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
}
.title {
font-size: 24px;
margin-bottom: 20px;
}
.btn {
display: block;
width: 200px;
height: 40px;
line-height: 40px;
text-align: center;
margin-bottom: 20px;
background-color: #4CAF50;
color: #fff;
border-radius: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.btn:hover {
background-color: #3e8e41;
cursor: pointer;
}
```
page3.js:
```javascript
//page3.js
Page({
navigateBack: function () {
wx.navigateBack({
delta: 1
})
}
})
```
上述代码实现了一个包含下拉提示框和多个页面跳转的微信小程序。注意:若要在微信小程序中正常运行,需要将代码保存成对应的文件名和文件格式,且需要在微信小程序开发者工具中导入项目并运行。
阅读全文