From cf6ea209637f02e20ed658e8ee060ed8eacc81fd Mon Sep 17 00:00:00 2001 From: Tevin <tingquanren@163.com> Date: Mon, 01 Nov 2021 10:42:26 +0800 Subject: [PATCH] 实现应用内超连接组件 --- layout/anchor/CAnchor.vue | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ layout/anchor/index.js | 10 ++++++++++ 2 files changed, 58 insertions(+), 0 deletions(-) diff --git a/layout/anchor/CAnchor.vue b/layout/anchor/CAnchor.vue new file mode 100644 index 0000000..d8158d5 --- /dev/null +++ b/layout/anchor/CAnchor.vue @@ -0,0 +1,48 @@ +/** + * CAnchor - 应用内超连接 + * @author Tevin + */ + +<template> + <view + class="c-anchor" + @tap="evt => handleGoTo()" + > + <slot /> + </view> +</template> + +<script> +import Taro from '@tarojs/taro'; + +export default { + name: 'CAnchor', + props: { + href: String, + rel: { + type: String, + default: 'navigate', + }, + }, + data() { + return {}; + }, + methods: { + handleGoTo() { + if (!this.href) { + return; + } + if (this.rel === 'navigate') { + if (this.href === 'back') { + Taro.navigateBack(); + } else { + Taro.navigateTo({ url: this.href }); + } + } else if (this.rel === 'redirect') { + Taro.redirectTo({ url: this.href }); + } + }, + }, + mounted() {}, +}; +</script> diff --git a/layout/anchor/index.js b/layout/anchor/index.js new file mode 100644 index 0000000..c3bf00b --- /dev/null +++ b/layout/anchor/index.js @@ -0,0 +1,10 @@ +/** + * CAnchor + * @author Tevin + */ + +import CAnchor from '@components/layout/anchor/CAnchor.vue'; + +export { + CAnchor, +} \ No newline at end of file -- Gitblit v1.9.1