uni.showModal 样式
时间: 2023-12-06 13:36:54 浏览: 679
uni.showModal是uni-app中用于显示模态弹窗的API,可以通过自定义样式来改变弹窗的外观。以下是一个自定义uni.showModal样式的例子:
1.在项目的common/style.scss文件中定义全局样式:
```scss
.uni-modal{
.uni-modal__bd{
color: blue;
font-size: 32rpx;
font-weight: bold;
padding: 64rpx 0 ;
}
}
```
2.在main.js中引入show-modal组件并创建组件:
```javascript
import Vue from 'vue'
import App from './App'
import initModal from './components/show-modal/initModal.vue'
Vue.component('show-modal', initModal)
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
...App
})
app.$mount()
```
3.在show-modal组件中使用自定义样式:
```html
<template>
<view>
<uni-modal :show="show" :title="title" :content="content" :confirm-text="confirmText" :cancel-text="cancelText" @confirm="confirm" @cancel="cancel" @close="close"></uni-modal>
</view>
</template>
<script>
export default {
props: {
show: {
type: Boolean,
default: false
},
title: {
type: String,
default: ''
},
content: {
type: String,
default: ''
},
confirmText: {
type: String,
default: '确定'
},
cancelText: {
type: String,
default: '取消'
}
},
methods: {
confirm() {
this.$emit('confirm')
},
cancel() {
this.$emit('cancel')
},
close() {
this.$emit('close')
}
}
}
</script>
<style lang="scss">
@import '../../common/style.scss';
uni-modal {
.uni-modal__bd {
color: red;
font-size: 28rpx;
font-weight: bold;
padding: 32rpx;
}
}
</style>
```
在上述代码中,我们在show-modal组件的style标签中重新定义了uni-modal__bd类的样式,将字体颜色改为红色,字体大小改为28rpx,字体加粗,内边距改为32rpx。
阅读全文