我的控制器:
import { Controller } from "@hotwired/stimulus";
import consumer from "channels/consumer";
export default class extends Controller {
static targets = ["users", "roomId"];
connect() {
console.log("");
this.subscription = consumer.subscriptions.find("RoomChannel");
}
};
我的房间_频道.js:
import consumer from "channels/consumer"
consumer.subscriptions.create("RoomChannel", {
connected() {
// Called when the subscription is ready for use on the server
console.log("Connected to rooms channel");
}
},
我的HTML:
<div data-controller="room">
<!-- get data -->
</div>
console.log()中的结果:
Error connecting controller
TypeError: consumer.subscriptions.find is not a function
我做错了什么?
1条答案
按热度按时间vwhgwdsa1#
实际上,consumer.subscribes没有'find'方法,但它有几个不同的方法:['create',' add','remove',' reject','forget',' findAll','reload',' notifyAll','notify',' subscribe','confirmSubscription','sendCommand']
您可能希望使用findAll方法,但不要忘记此方法接受完整的通道标识符