安装

安装

#npm 安装

npm i -S dolphin-native-bridge  或者 npm install dolphin-native-bridge --save-dev

#yarn 安装

yarn add dolphin-native-bridge

#升级接口模块

  • 使用 cnpm install -S + 模块name + 版本号,推荐使用cnpm,此处使用npm在部分版本下有问题。
# 升级到最新版本

    cnpm install -S dolphin-native-bridge@latest 

# 升级到指定版本,例如: 

    cnpm install -S dolphin-native-bridge@ + 版本号

# 使用0.0.30版本:

    cnpm install -S dolphin-native-bridge@0.0.30
  • 手动修改package.json文件下的模块的版本号,然后执行以下命令:
cnpm install(推荐)
#或者
npm update 
#或者
npm install

注:

如果 npm 安装较慢,可以切换到淘宝源,使用cnpm安装

切换到淘宝镜像:npm config set registry https://registry.npm.taobao.org

#全局挂载

dolphin-native-bridge模块在新框架中已内置处理挂载到全局,可直接通过 this.$bridge 调用

//bridgeModule 已挂载在this.$bridge上,可以直接调用
let message = 'hello, world'

this.$bridge.showToast(message)

#兼容旧框架

#hello World 示例

<template>
    <div class="app">
        <text>{{title}}</text>
        <dof-button title="快速上手" @dofButtonClicked="clickHandler"></dof-button>
    </div>
</template>
<script>
import { DofButton } from 'dolphin-weex-ui'
import DolphinBridge from 'dolphin-native-bridge'
Vue.use(DolphinBridge)  // dolphin-native-bridge 版本不低于 v0.1.1

export default {
    components: {
        DofButton
    },
    data:() => ({
        message: 'hello world'
    }),
    methods: {
        clickHandler() {
            let { message } = this
            this.$bridge.showToast(message)
        }
    }
}
</script>
<style scoped>
.app {
    width: 750px;
}
</style>
posted on 2024-12-12 09:18  AtlasLapetos  阅读(16)  评论(0)    收藏  举报