1 回复
针对您提出的uni-app模板需求,以下是一个简单的uni-app项目模板示例,涵盖了页面结构、样式定义以及基本的数据绑定和事件处理。此模板包括一个首页(index),显示一个欢迎消息和一个按钮,点击按钮会跳转到另一个页面(details)。
1. 项目结构
uni-app-template/
├── pages/
│ ├── index/
│ │ ├── index.vue
│ ├── details/
│ ├── details.vue
├── App.vue
├── main.js
├── pages.json
├── manifest.json
└── uni.scss
2. main.js
import Vue from 'vue'
import App from './App'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
...App
})
app.$mount()
3. App.vue
<template>
<App />
</template>
<script>
export default {
name: 'App'
}
</script>
<style>
/* 全局样式 */
</style>
4. pages/index/index.vue
<template>
<view class="container">
<text>{{ message }}</text>
<button @click="navigateToDetails">Go to Details</button>
</view>
</template>
<script>
export default {
data() {
return {
message: 'Welcome to uni-app!'
}
},
methods: {
navigateToDetails() {
uni.navigateTo({
url: '/pages/details/details'
})
}
}
}
</script>
<style scoped>
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
}
</style>
5. pages/details/details.vue
<template>
<view class="container">
<text>Details Page</text>
<button @click="goBack">Go Back</button>
</view>
</template>
<script>
export default {
methods: {
goBack() {
uni.navigateBack()
}
}
}
</script>
<style scoped>
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
}
</style>
6. pages.json
{
"pages": [
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "Home"
}
},
{
"path": "pages/details/details",
"style": {
"navigationBarTitleText": "Details"
}
}
]
}
此模板提供了一个基本的uni-app项目结构,包括页面导航、数据绑定和事件处理。您可以根据实际需求进一步扩展和优化。