안녕하세요. 블레이저 화면 데이터 갱신에 대해 문의드립니다.
정적클래스로 서버쪽에 클래스를 하나 올리고 해당 클래스에 바인딩을 했습니다.
서버쪽에 있는 클래스가 공유되기 때문에 해당 페이지에 접속한 사용자중 누군가
정보를 변경하면 접속한 모든 사용자의 정보가 변경될지 알았습니다.
예전의 웹 기술이야 데이터를 변경한 사람외 다른 사람이 보는 페이지는 새로고침
하기 전까지는 반영이 안되는게 당연했지만 이 사이트만 봐도 게시글을 누군가가 편
집하고 있으면 편집중이라고 뜨던데… 원래 안되는게 맞는건지요??
public static class shareCount
{
public static shareTest test = new shareTest();
}
public class shareTest : INotifyPropertyChanged
{
public int a = 0;
public event PropertyChangedEventHandler? PropertyChanged;
public int A
{
get { return a; }
set { a = value; OnPropertyChanged("A"); System.Diagnostics.Debug.Print("!!!"); }
}
public void Aup()
{
A = A + 1;
}
public void Adown()
{
A = A - 1;
}
private void OnPropertyChanged(string propertyname)
{
if (PropertyChanged != null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyname));
}
}
}
[blazorPage]
<PageTitle>Home</PageTitle>
<h1>Hello, world!</h1>
Welcome to your new app.
<input @bind-value =@shareCount.test.A />
<button class="btn btn-primary" @onclick="IncrementCount">UP!!!</button>
<button class="btn btn-primary" @onclick="decrementCount">DWON!!!</button>
@code {
private int currentCount = 0;
private void IncrementCount()
{
shareCount.test.Aup();
}
private void decrementCount()
{
shareCount.test.Adown();
}