如何在Vuejs中传递json对象?



<template>
<div id="app">
<div id="bee-plugin-container"></div>
</div>
</template>
<script>
// import axios from "axios";
// import Bee from "@mailupinc/bee-plugin";
import $ from 'jquery'
export default {
name: "App",
data() {
return {
info: null,
};
},
mounted() {
var bee;
var endpoint = "https://auth.getbee.io/apiauth";
var payload = {
client_id: "<client>", // Enter your client id
client_secret: "smesVY4mhFdfxvgF", // Enter your secret key
grant_type: "Basicbmdll" // Do not change
};
$.post(endpoint, payload)
.done(function(data) {
var token = data;
// continue initialization here...
console.log('token: ', data);
// Define a simple BEE Plugin configuration...
var config = {
uid: token.userName,
container: 'bee-plugin-container',
language: "en-US",
// eslint-disable-next-line
onSave: (jsonFile, htmlFile) => {
// eslint-disable-next-line
const params = {
layout_json: jsonFile,
layout_html: htmlFile,
campaign_id: 1,
};
console.log('saving...', params);
},
}
window.BeePlugin.create(token, config, function(instance) {
bee = instance;
// You may now use this instance...
var template = {
// Any valid template, as JSON object
// Any valid template, as JSON object
// Any valid template, as JSON object
// Any valid template, as JSON object
// Any valid template, as JSON object
// Any valid template, as JSON object
// Any valid template, as JSON object
// Any valid template, as JSON object
// Any valid template, as JSON object
// Any valid template, as JSON object
// Any valid template, as JSON object
// Any valid template, as JSON object
};
bee.start(template);
});
});
}
};
</script>
<style>
</style>

如何在Vuejs中传递json对象?

我做了一个api调用,来调用bee-plugin实例。在哪里我需要传递json对象,我不知道在哪里我需要传递json对象。

下面是API调用工作正常的代码,但问题是如何传递json obj。

var template = {
// Any valid template, as JSON object

};
bee.start(template);

Codesandbox链接:https://codesandbox.io/s/bee-plugin-in-vuejs-rjn99?file=/src/App.vue

您必须初始化Bee插件并创建它的实例。并根据文档使用实例来启动模板。您可以在mounted方法上这样做。

mounted(){
const beeInstance = new Bee();
const config = {}; // Your configs
const template = {}; // Your template
// ...
beeInstance
.getToken(payload.client_id, payload.client_secret)
.then(() => beeInstance.start(config, template));
}

这是工作代码依赖的链接。

最新更新