如果没有package.json的话,就先初始化一下 npm init -y
然后npm下载
npm install --save pixi.js
检查一下是什么版本
npm ls pixi.js
我最开始是7.2.4,但是会报错exports is not defined
,所以我降到了4.8.9版本
页面上会出现一个黑色的正方形,就表示引入成功啦
<template>
<view>
<view id='pixi'></view>
</view>
</template>
<script>
import * as PIXI from "pixi.js"
export default {
data() {
return {
}
},
mounted() {
this.initPixi()
},
methods: {
initPixi() {
const PIXI = require('pixi.js')
console.log(PIXI);
let type = "WebGL"
if (!PIXI.utils.isWebGLSupported()) {
type = "canvas"
}
PIXI.utils.sayHello(type)
this.app = new PIXI.Application({
width: 456, // default: 800
height: 456, // default: 600
})
document.getElementById("pixi").appendChild(this.app.view);
}
}
}
</script>