Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
cloudbase-vue-next
Advanced tools
[云开发 Vue 插件](https://github.com/TencentCloudBase/cloudbase-vue) 是云开发官方维护的 Vue 插件,提供全局入口、Vue 逻辑组件等功能。
云开发 Vue 插件 是云开发官方维护的 Vue 插件,提供全局入口、Vue 逻辑组件等功能。
npm install --save cloudbase-vue-next
下面我们使用 LoginState
组件,来动态绑定当前页面的登录态。
'未登录'
'已登录'
main.js
import {createApp} from "vue"
import Cloudbase from "cloudbase-vue-next"
import App from "./App.vue"
const app = createApp(App)
app.use(Cloudbase, {
env: "your-env-id",
region: "your-env-region"
})
app.mount('#app');
App.vue
<template>
<div id="app">
<h1>Hello world</h1>
<LoginState v-slot="{ loginState }">
<h1>{{ loginState ? "已登录" : "未登录" }}</h1>
</LoginState>
<button @click="callFn">调用云函数</button>
</div>
</template>
<script>
export default {
async created() {
// 以匿名登录为例
await this.$cloudbase
.auth({ persistence: "local" })
.anonymousAuthProvider()
.signIn();
},
methods: {
callFn() {
this.$cloudbase
.callFunction({
name: "vue-echo",
data: { meg: "Hello world" },
})
.then((res) => {
const result = res.result; //云函数执行结果
console.log(result);
});
},
},
};
</script>
在setup中使用
<template>
<div id="app">
<h1>Hello world</h1>
<LoginState v-slot="{ loginState }">
<h1>{{ loginState ? "已登录" : "未登录" }}</h1>
</LoginState>
<button @click="callFn">调用云函数</button>
</div>
</template>
<script>
import { useCloud } from "cloudbase-vue-next"
export default {
setup(){
const cloudbase = useCloud({
env: "your-env-id",
region: "your-env-region"
});
//登录授权
cloudbase
.auth({ persistence: "local" })
.anonymousAuthProvider()
.signIn();
//请求函数
const callFn=()=>{
cloudbase
.callFunction({
name: "vue-echo",
data: { meg: "Hello world" },
})
.then((res) => {
const result = res.result; //云函数执行结果
console.log(result);
});
}
return {
callFn
}
}
};
</script>
可以在 Vue 组件的 this.$cloudbase
中,获取 Cloudbase 实例
export default {
data() {
return {
docs: []
}
},
async created() {
// 登录
await this.$cloudbase.auth({ persistence: "local" }).signInWithTicket(ticket)
// 数据库查询
const queryResult = await this.$cloudbase.database().collection('test').where({}).get()
this.docs = queryResult.data
}
}
组件 | 功能 |
---|---|
LoginState | 获取并绑定登录状态 |
DatabaseQuery | 数据库查询 |
DatabaseWatch | 数据库实时推送 |
CloudFile | 获取云存储中的文件 |
获取登录状态
暂无
slot | type | 描述 |
---|---|---|
loginState | null or LoginState | 当前是否登录 |
loading | boolean | 是否加载中 |
<LoginState v-slot="{ loginState, loading }">
<p>{{ loading ? '加载中' : (loginState ? '已登录' : '没登录') }}</p>
</LoginState>
数据库查询
prop | type | 描述 |
---|---|---|
collection | string | 集合名 |
query | function | 返回自定的查询条件,如 _ => ({ foo: _.gt(2) }) |
slot | type | 描述 |
---|---|---|
docs | Array<doc> | 文档组成的数组 |
loading | boolean | 是否加载中 |
error | null or Error | 错误 |
<DatabaseQuery
v-slot="{ docs, loading, error }"
collection="messages"
:query="_ => ({ timestamp: _.gt(1573635456709) })"
>
<p v-for="{ text } in docs">
{{ text }}
</p>
</DatabaseQuery>
数据库实时监听
prop | type | 描述 |
---|---|---|
collection | string | 集合名 |
query | function | 返回自定的查询条件,如 _ => ({ foo: _.gt(2) }) |
slot | type | 描述 |
---|---|---|
docs | Array<doc> | 文档组成的数组 |
loading | boolean | 是否加载中 |
error | null or Error | 错误 |
<DatabaseWatch
v-slot="{ docs, loading, error }"
collection="messages"
:query="_ => ({ timestamp: _.gt(1573635456709) })"
>
<p v-for="{ text } in docs">
{{ text }}
</p>
</DatabaseWatch>
根据 FileID
,获取云存储文件的真实 URL
slot | type | 描述 |
---|---|---|
id | string | 云存储 ID,形如 cloud://... |
slot | type | 描述 |
---|---|---|
url | string | 文件的真实 URL |
loading | boolean | 是否加载中 |
error | null or Error | 错误 |
<CloudFile
id="cloud://file-cloud-path"
v-slot="{ url, loading }"
>
{{ url ? url : 'loading...' }}
</CloudFile>
FAQs
[云开发 Vue 插件](https://github.com/TencentCloudBase/cloudbase-vue) 是云开发官方维护的 Vue 插件,提供全局入口、Vue 逻辑组件等功能。
The npm package cloudbase-vue-next receives a total of 14 weekly downloads. As such, cloudbase-vue-next popularity was classified as not popular.
We found that cloudbase-vue-next demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.