帖子
帖子
用户
博客
课程
显示全部楼层
8
帖子
0
勋章
70
Y币

[多端开发] dispatch script failed. ReferenceError: $api is not defined at main.js

[复制链接]
发表于 2022-8-11 11:49:46
<template>
    <safe-area class="page">
        <view class="header">
            <text class="title">首页</text>
        </view>
        <view class="body" id="mybody">
            <text class="h1">{module}</text>
            <img class="img" src="../../image/img.png" />
            <text class="p">{text}</text>

        </view>
    </safe-area>
</template>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript">
import config from '../../script/configModule'
export default {
    name: 'main',
    apiready() {
        this.data.module = config.data[0].moduleText;
        $api.html($api.byId('mybody'),'<h1>world</h1>');
    },
    data() {
        return {
            module: '',
            text: '我是text'
        };
    },
    methods: {}
};
</script>
<style>
.page {
    height: 100%;
    background: #fff;
}

.header {
    height: 44px;
    justify-content: center;
    align-items: center;
}

.title {
    font-size: 16px;
    font-weight: bold;
    color: #333;
}

.body {
    background: #f5f6f7;
    flex: 1;
}

.h1 {
    font-size: 22px;
    font-weight: bold;
    color: #333;
    text-align: center;
    margin: 50px;
}

.img {
    max-width: 100%;
}

.p {
    color: #aaa;
    text-align: center;
    font-size: 16px;
    margin: 15px;
}
</style>



../../script/api.js  这个引入了吗
是怎么引入的

index.js
const $index = {
    a(){
        console.log("这里是a方法,所以输出:a");
    },
    b(){
        console.log("这里是b方法,所以输出:b");
    }
};
export default $index;
avm页面里:
引入:
import $index from '../../res/index.js';
使用:
$index.a();
8
帖子
0
勋章
70
Y币
嗯嗯 知道了 需要通过import引入
技术咨询-特特 · 2022-8-11 13:24index.js
const $index = {
    a(){
8
帖子
0
勋章
70
Y币
apiready() {
                this.data.module = config.data[0].moduleText;
                // document.getElementById('mybody').innerHTML='<h1>world</h1>'
                $api.append($api.byId('mybody'), '<h1>111hello world</h1>');

        },


然后报:[2022-8-11 13:40:52][ERROR] dispatch apiready failed. TypeError: el.insertAdjacentHTML is not a function at main.js:342
技术咨询-特特 · 2022-8-11 13:24index.js
const $index = {
    a(){
3.0 里边不支持前端框架  api.js
您需要登录后才可以回帖 登录

本版积分规则