uni-app自动引入全局组件“easycom”

easycom
只要组件安装在项目的components目录下,并符合components/组件名称/组件名称.vue目录结构。就可以不用引用、注册,直接在页面中使用。
easycom是在pages.json中配置

"easycom": {
	    "autoscan": true, //是否自动扫描组件
	    "custom": {//自定义扫描规则
	      "^uni-(.*)": "@/components/uni-$1.vue"
	    }
	}

以上就是自动找在components目录下,符合命名规范的
uni-****.vue的文件并注册成组件
在这里插入图片描述
自动注册的 uni-footer组件。
不需要引入直接在index.vue中使用

<uni-footer></uni-footer>
uni-app 中,可以通过 Native.js 实现安卓本地通知,具体步骤如下: 1. 在 App.vue 文件中,监听应用启动事件,调用 Native 模块中的 startForeground 方法开启前台服务: ```javascript export default { onLaunch() { const nativeModule = uni.requireNativePlugin("NativeModule"); nativeModule.startForeground(); } } ``` 2. 在 Native 模块中,实现 startForeground 方法,并在该方法中创建通知渠道和通知: ```javascript const Context = require("@android/context"); const Notification = require("@android/app/Notification"); const NotificationManagerCompat = require("@android/app/NotificationManagerCompat"); const NotificationChannel = require("@android/app/NotificationChannel"); function startForeground() { const service = getContext().getService(); const channel = new NotificationChannel("channel_id", "channel_name", NotificationManagerCompat.IMPORTANCE_HIGH); const notificationManager = NotificationManagerCompat.from(Context); const notification = new Notification.Builder(Context, "channel_id") .setSmallIcon(android.R.drawable.ic_dialog_info) .setContentTitle("Foreground Service") .setContentText("Service is running in foreground") .build(); service.startForeground(1, notification); } ``` 3. 在 Native 模块中,实现 showNotification 方法,用于创建本地通知: ```javascript function showNotification(title, content) { const notificationManager = NotificationManagerCompat.from(Context); const notification = new Notification.Builder(Context, "channel_id") .setSmallIcon(android.R.drawable.ic_dialog_info) .setContentTitle(title) .setContentText(content) .build(); notificationManager.notify(1, notification); } ``` 其中,第一个参数为通知的 ID,第二个参数为 Notification 对象。 4. 在 App.vue 文件中,调用 Native 模块中的 showNotification 方法创建本地通知: ```javascript export default { methods: { showLocalNotification() { const nativeModule = uni.requireNativePlugin("NativeModule"); nativeModule.showNotification("Local Notification", "This is a local notification"); } } } ``` 这样就可以通过 Native.js 实现安卓本地通知了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值