【发布时间】:2021-09-30 13:03:12
【问题描述】:
我开始在我现有的 PhP 项目中集成一些 Vue 3 组件。
代码如下例所示
phpfile.php
<?php
//..get some User and Session Data
//.. get some other fancy data from DB
$data = array(
'userData' => $userdata,
'otherData' => $otherData
);
include 'template.php';
?>
模板.php
<html>
<head>
<script>Link to vue js CDN</script>
<-- Head stuff -->
</head>
<body>
<div id="vueApp">
<div v-if="isAdmin"> <-- show some Admin things --></div>
<div v-else> <-- show some not Admin things --></div>
</div>
<script src="../vueComponent.js"></script>
</body>
</html>
vueComponent.js
const app = Vue.createApp({
data() {
return {
isAdmin: false,
}
},
methods: {
},
mounted() {
}
})
app.mount('#vueApp')
如何将 $data['userdata'] 放入 vue 组件中?
感谢您的帮助。
【问题讨论】:
-
将其作为道具传递或将其作为 API 端点,组件可以从中调用数据并填充组件数据
-
嗨,我不想编写额外的 api 来获取我已经为加载页面而获取的相同数据。那么,我如何将它们作为 pro 传递给组件? js 文件中的 不起作用
-
你不能是我这么说的原因,至少在你想要的上下文中